Stored Procedures | issues
Calling stored procedures in C # is primarily a matter of parameter usage (input parameters, output parameters, return values)
It is assumed that Conn is a defined connection, proc is the stored procedure name
1, call no parameter no return of stored procedures
SqlCommand cmd=new SqlCommand (proc,conn);
Cmd.commandtype=commandtype.storedprocedure;//tells the execution of the stored procedure
Conn. Open ();
Cmd. ExecuteNonQuery ();
2, the use of input parameters and output parameters
Suppose there is a stored procedure
Create proc TestProc
//(
@test_in varchar (20),
@test_out varchar (OUTPUT)
//)
SqlCommand cmd=new SqlCommand (proc,conn);
Cmd.commandtype=commandtype.storedprocedure;//tells the execution of the stored procedure
SqlParameter sp=new SqlParameter ("@test_in", sqldbtype.varchar,20);
Sp. value= "Input Parameters";
Cmd. Parameters.Add (SP);//Add Parameters to command object
SqlParameter out=new SqlParameter ("@test_out", sqldbtype.varchar,20);
Out. direction=parameterdirection.output//Specifies that the parameter is an output parameter
Cmd. Parameters.Add (out);//Add Parameters to command object
Conn. Open ();
Cmd. ExecuteNonQuery ();
String Result=cmd. parameters["@test_out"]. Value.tostring ()///This is to get the returned output parameter value
3. Get return value
To get return values, you need to add returns parameters, such as receiving 1 returned values with a return type of int
SqlParameter returnparameter=new SqlParameter ("ReturnValue", sqldbtype.int,4);
RETURNPARAMETER.DIRECTION=PARAMETERDIRECTION.RETURNVALUE//Specifies the return value of this parameter
#endregion
Public Classdb ()
{
}
#region public bool Checklanding (string strlandname, String strlandpwd)