There is a web application, the page contains a GridView with a connected database via the SqlDataSource. How can I call a stored procedure ( StoredProcedure2 ) and pass a parameter to this procedure when I call it? I called the stored procedure (another stored procedure called StoredProcedure1 , which did not require passing parameters to it by:

 SqlDataSource1.SelectCommand = "StoredProcedure1"; ALTER PROCEDURE dbo.StoredProcedure1 AS SELECT ID, Name, Surname FROM Table1 WHERE Name='Sania' ALTER PROCEDURE dbo.StoredProcedure2 @Name VARCHAR(15) AS SELECT ID, Name, Surname FROM Table1 WHERE Name= @Name 

1 answer 1

Perhaps someone will come in handy, an example of calling a stored procedure without parameters for c #, SelectPole2 is the name of the stored procedure

  SqlConnection conn = new SqlConnection("Server=localhost;" + "database=Агрономія4;" + "Integrated Security=True"); System.Data.SqlClient.SqlCommand myCmd = new System.Data.SqlClient.SqlCommand(); conn.Open(); myCmd.Connection = conn; myCmd.CommandType = CommandType.StoredProcedure; myCmd.CommandText = "SelectPole2"; SqlDataReader rez; rez = myCmd.ExecuteReader(CommandBehavior.CloseConnection); GridView1.DataSource = rez; GridView1.DataBind(); conn.Close();