存储过程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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章