The stored procedure p_sys_login is defined as follows:
Create procedure p_sys_login
@ Arguserid varchar (20), -- User Name
@ Argpassword varchar (20), -- Password
@ Argresult varchar (50) Output -- logon result
As
/*
Write the specific content yourself
*/
The following shows how to use the most concise and effective code in C # To execute the stored procedure and return data:
/// <Summary>
/// User Logon Verification
/// </Summary>
/// <Param name = "userid"> User Name </param>
/// <Param name = "password"> password </param>
Public void login (string userid, string password)
{
// The database connection string is stored in Web. config.
String cnnstring = configurationsettings. etettings ["connectionstring"];
Sqlconnection CNN = new sqlconnection (cnnstring );
String SQL = string. Format ("Exec p_sys_login {0}, {1}, @ result output", userid, password );
Sqlcommand cmd = new sqlcommand (SQL, CNN );
// Create and add parameters corresponding to "@ result output"
Sqlparameter paramresult = new sqlparameter ("@ result", sqldbtype. varchar, 50 );
Paramresult. Direction = parameterdirection. output;
Cmd. Parameters. Add (paramresult );
CNN. open ();
Cmd. executenonquery ();
CNN. Close ();
// Obtain the results returned by the Stored Procedure
String result = paramresult. value. tostring ();
//......
}