本文实例讲述了C#执行存储过程并将结果填充到GridView的方法。分享给大家供大家参考,具体如下:
代码如下 | 复制代码 |
SelectSql sq =newSelectSql(); SqlConnection conn =newSqlConnection(sq.lc); conn.Open(); SqlDataAdapter rd =newSqlDataAdapter(); DataSet ds=newDataSet(); SqlCommand sqlcom =newSqlCommand("dbo.selectjf",conn); sqlcom.Parameters.Add("@name", SqlDbType.VarChar,20).Value = NameText.Text; sqlcom.Parameters.Add("@sfzh",SqlDbType.VarChar,30).Value = SfText.Text; sqlcom.CommandType = CommandType.StoredProcedure; rd.SelectCommand = sqlcom; rd.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); conn.Close(); ds.Dispose(); rd.Dispose(); |