How to execute (run) stored procedure in ASP .NET and in C# Example/sample code

How to execute (run) stored procedure in ASP .NET and in C# Example/sample code
How to pass parameters to stored procedures in ASP.NET and in C# Example/sample code


ASP.NET and C# Sample Code:



SqlConnection connection = new SqlConnection(“<ConnectionString>”);
connection.Open();
SqlCommand sqlCommand = new SqlCommand("<StoredProcedureName>", connection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("<Parameter1>", SqlDbType.VarChar).Value = <value>;
sqlCommand.Parameters.Add("<Parameter2>", SqlDbType.VarChar).Value = <value>;

SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
sqlAdapter.Fill(ds);
connection.Close();

No comments:

Post a Comment