
| 程序代码:private void buycatalog() { SqlConnection conndb= new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]); conndb.Open(); SqlDataAdapter strselect = new SqlDataAdapter("productclass",conndb); strselect.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); strselect.Fill(ds); DlstBuycatalog.DataSource =ds; DlstBuycatalog.DataKeyField ="PdtCat_ID"; DlstBuycatalog.DataBind(); conndb.Close(); } 以上这个方法,就是通过SqlDataAdapter对像调用了SQL中存储过程productclass,通过DataSet将数据填充在ds中,同时指定DataList控件DlstBuycatalog的数据源是ds,主键是PdtCat_Id,最后再重新绑定Datalist控件.由这个方法我们可以看到用SqlDataAdapter调用存储过程中的关键是: SqlDataAdapter strselect = new SqlDataAdapter("productclass",conndb); strselect.SelectCommand.CommandType = CommandType.StoredProcedure; 当存储过程中有参数时,我们又应该乍样做呢?其实这个跟SqlCommand的差不多,我们只要再加一句 Strselect.SelectCommand.Parameter.Add(“@pdt_name”,txtpdtname.Text()); |