本文实例讲述了C#执行存储过程并将结果填充到GridView的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
SelectSql sq = new SelectSql(); SqlConnection conn = new SqlConnection(sq.lc); conn.Open(); SqlDataAdapter rd = new SqlDataAdapter(); DataSet ds= new DataSet(); SqlCommand sqlcom = new SqlCommand( "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(); |
希望本文所述对大家C#程序设计有所帮助。