Visual C # tutorial on Dynamically Operating SQL Server database instances (2): execution of stored procedures without Parameters
The previous article introduced the SQL statement execution method without parameters. This article describes the code of the stored procedure execution method without parameters. It calls the SQL helper class to execute SqlHelper. executeNonQuery () method. The example is;
Int val = SqlHelper. ExecuteNonQuery (conn, CommandType. StoredProcedure, SQLexec, null );
The four parameters are passed:
"Conn"-is a link character;
"CommandType. StoredProcedure"-it is an SQL command type. The SQL stored procedure is executed;
"SQLexec"-the SQL stored procedure character;
"Null"-provides the list of parameters used in the SqlCommand in the form of arrays, which is not empty because it is not in the form of data.
Protected void btnExecuteProc_Click (object sender, EventArgs e)
{
// Obtain the name of the stored procedure to be executed
String SQLexec = "sp_getGISnews ";
SqlCommand cmd = new SqlCommand ();
// Define the storage range of object Resources. When the value of using is reached, the resources occupied by the other party are released.
Using (SqlConnection conn = new SqlConnection (SqlHelper. ConnectionStringLocalTransaction) // note that because conn is already used in SqlHelper. cs, it cannot be renamed here, so use conn1 instead.
{
// Open the link
Conn. Open ();
// Call the execution method. Because there is no parameter, the last item is set to null.
Int val = SqlHelper. ExecuteNonQuery (conn, CommandType. StoredProcedure, SQLexec, null );
Response. Write ("");
}
}
When ExecuteNonQuery () executes select, the result is always returned-1. ExecuteNonQuery () for Update, Insert, and Delete statements, the returned value is the number of rows affected by the command. For all other types of statements, the return value is-1. For more information, see the relevant content of your website.