Stored Procedure
A query stored procedure.
Returns the queried records.
In. net, I receive this returned record set.
Answer:
(1) execute a stored procedure without Parameters CodeAs follows:
Sqlconnection conn = new sqlconnection ("connectionstring ");
Sqldataadapter da = new sqldataadapter ();
Da. selectcommand = new sqlcommand ();
Da. selectcommand. Connection = conn;
Da. selectcommand. commandtext = "nameofprocedure ";
Da. selectcommand. commandtype = commandtype. storedprocedure;
(2) The code for executing a stored procedure with parameters is as follows:
Sqlconnection conn = new sqlconnection ("connectionstring ");
Sqldataadapter da = new sqldataadapter ();
Da. selectcommand = new sqlcommand ();
Da. selectcommand. Connection = conn;
Da. selectcommand. commandtext = "nameofprocedure ";
Da. selectcommand. commandtype = commandtype. storedprocedure;
Param = new sqlparameter ("@ parametername", sqldbtype. datetime );
Param. Direction = parameterdirection. input;
Param. value = convert. todatetime (inputdate );
Da. selectcommand. Parameters. Add (PARAM );
To add output parameters:
Param = new sqlparameter ("@ parametername", sqldbtype. datetime );
Param. Direction = parameterdirection. output;
Param. value = convert. todatetime (inputdate );
Da. selectcommand. Parameters. Add (PARAM );
To obtain the return value of the parameter store process:
Param = new sqlparameter ("@ parametername", sqldbtype. datetime );
Param. Direction = parameterdirection. returnvalue;
Param. value = convert. todatetime (inputdate );
da. selectcommand. Parameters. Add (PARAM);