How to call a Select statement Stored Procedure using SqlDataAdapter?

Syedshakeer
Posted by Syedshakeer under C# category on | Views : 13135
Creating a select statement storedprocedure:

CREATE PROCEDURE selectemp1 AS
ASselect * from emp


Here 'selectemp1' is a procedure name and emp is the Table name.

How to call a Procedure name usign SqlDataAdapter and display the data in Gridview:

SqlConnection conn = new SqlConnection("Data Source=INTHIYAAZ;Initial Catalog=shakeer;
User ID=sa;Password=sa");
conn.Open();
//calling the stored procedure name 'selectemp1' in sqlcommand
SqlCommand cmd = new SqlCommand("selectemp1",conn );
SqlDataAdapter adapter = new SqlDataAdapter(cmd );
DataSet ds = new DataSet();
adapter.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

Comments or Responses

Login to post response