Tuesday, June 12, 2012 4:31 PM
I want to define a stored procedure in sql server 2008 so that it can be called from my c# code and display the table in a Data grid . so far i was doig with sending a query statement like select * from Tablename after creating the necessary connections and data adapters fill method. i want to replace it with a stored procedure to avoid repeated connection overhead
Tuesday, June 12, 2012 5:30 PM
A stored procedure is stored in SQL Server. So you will not be able to use it to define your data access methods !!
A stored procedure is a set of SQL statements. It simplifies the "select * from tablename" part, but cannot replace the connection setting. A stored procedure may accept arguments, which you provide in the calling code.
Using myConnexion As SqlConnection = New SqlConnection(myConnexionString) Using cmd As SqlCommand = New SqlCommand() cmd.Connection = myConnexion cmd.CommandType = CommandType.StoredProcedure myConnexion.Open() cmd.CommandText = "NameOfStoredProcedure" cmd.Parameters.Clear() cmd.Parameters.Add(New SqlParameter("nameOfParameter", SqlDbType.Int)).Value = valueOfParameter cmd.ExecuteNonQuery() myConnexion.Close() End Using End Using