C # Call the SQL server stored procedure,
Go straight to the topic, record
- Namespace: using System. Data. SqlClient;
- Database LINK string: database link string format: server = {0}; database = {1}; uid = {2}; pwd = {3} // 0: server, 1: Database Name, 2: User Name, 3: Password
- Call:
Using (SqlConnection connection = new SqlConnection (SqlServerHelper. connectionString) {connection. open (); SqlCommand cmd = new SqlCommand ("Stored Procedure name", connection); cmd. parameters. add ("@ param1", SqlDbType. int); cmd. parameters ["@ param1"]. value = "param1_value"; cmd. parameters ["@ param1"]. direction = ParameterDirection. input; cmd. parameters. add ("@ param2", SqlDbType. int); cmd. parameters ["@ param2"]. value = "param2_value"; cmd. parameters ["@ param2"]. direction = ParameterDirection. input; // Outpu cmd. connection = connection; cmd. commandType = CommandType. storedProcedure; // The call type SqlDataReader dr = cmd. executeReader (); // executes the SQL statement and returns the result set // int rerows = cmd. executeNonQuery (); // execute the SQL statement, the number of affected rows while (dr. read () {// process the returned results // dr [0], dr ["col_name"]} dr. close (); // Close the execution of connection. close (); // Close the database}