存儲過程1——讀取數據

protected System.Web.UI.WebControls.DataGrid DataGrid1;
  SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["dsn"]);
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此處放置用戶代碼以初始化頁面
   if(!Page.IsPostBack)
   {
    SqlCommand myCommand = new SqlCommand("actList",conn);
    myCommand.CommandType = CommandType.StoredProcedure ;
    
    conn.Open();

    SqlDataReader MyDataReader = myCommand.ExecuteReader();
    DataGrid1.DataSource = MyDataReader;
    DataGrid1.DataBind();
    
    MyDataReader.Close();
    conn.Close(); 
   }

發佈了30 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章