EXEC Proceudre2
System.Data.SqlClient.SqlConnection Sqlcon = new System.Data.SqlClient.SqlConnection ("server= (local);d atabase= pubs;uid=sa;pwd=; ");
System.Data.SqlClient.SqlConnection Sqlcon = new System.Data.SqlClient.SqlConnection (@ "Data Source=192.168.1.8\mis ; Initial Catalog=erp; User Id=sa; password=3860; ");
System.Data.SqlClient.SqlCommand sqlcmd = new System.Data.SqlClient.SqlCommand ("Pscrbcdconform", Sqlcon);
Sqlcmd.commandtype = System.Data.CommandType.StoredProcedure;
Add stored procedure input and output parameter types and input parameter values
sqlcmd. Parameters.Add ("@DH", System.Data.SqlDbType.VarChar, 50). Value = STR_DH;
sqlcmd. Parameters.Add ("@CONFORM_CODE", System.Data.SqlDbType.VarChar, 50). Value = "Y";
sqlcmd. Parameters.Add ("@CONFORM_Name", System.Data.SqlDbType.VarChar, 50). Value = "BPM process audit";
sqlcmd. Parameters.Add ("@CONFORM_Date", System.Data.SqlDbType.VarChar, 50). Value = Str_finishdate.trim ();
sqlcmd. Parameters.Add ("@ReturnValue", System.Data.SqlDbType.Int, 4). Value = "1";
Specify whether the parameter type is an input parameter or an output parameter
sqlcmd. parameters["@DH"]. Direction = System.Data.ParameterDirection.Input;
sqlcmd. parameters["@CONFORM_CODE"]. Direction = System.Data.ParameterDirection.Input;
sqlcmd. parameters["@CONFORM_Name"]. Direction = System.Data.ParameterDirection.Input;
sqlcmd. parameters["@CONFORM_Date"]. Direction = System.Data.ParameterDirection.Input;
sqlcmd. parameters["@ReturnValue"]. Direction = System.Data.ParameterDirection.ReturnValue;
//sqlcmd. Parameters.Add ("@rus", System.Data.SqlDbType.Int);
//sqlcmd. Parameters.Add ("@outrus", System.Data.SqlDbType.Int);
//sqlcmd. Parameters[0]. Direction = System.Data.ParameterDirection.ReturnValue;
//sqlcmd. PARAMETERS[1]. Direction = System.Data.ParameterDirection.Output;
Sqlcon. Open ();
int res= (int) sqlcmd. ExecuteNonQuery ();//The return value of the stored procedure is not returned at this time, only the number of rows affected by the return Delete,update,insert
Accept the return value after executing the stored procedure
int n = System.Convert.ToInt32 (sqlcmd. parameters["@ReturnValue"]. Value); ------Me-----
sqlcmd. ExecuteNonQuery ();
string res = sqlcmd. Parameters[0]. Value.tostring ();//So you can get the return value of the stored procedure
Sqlcon. Close ();
//
20150825 C # calls a stored procedure template with parameters