C's method of executing stored procedures and populating the results into GridView

  • 2021-12-05 07:03:19
  • OfStack

This article illustrates how C # executes stored procedures and populates the results into GridView. Share it for your reference, as follows:


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();

For more readers interested in C # related content, please check out the topics on this site: "C # Common Control Usage Tutorial", "WinForm Control Usage Summary", "C # Data Structure and Algorithm Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "C # Programming Thread Use Skills Summary"

I hope this article is helpful to everyone's C # programming.


Related articles: