The stored procedure p_sys_login is defined as follows:
Create Procedure P_sys_login
@arguserid varchar (20), - Username
@argpassword varchar (20), - password
@ArgResult varchar (50) Output - Login Results
AS
/ *
...
* /
The following demonstrates how to perform this stored procedure with the simplest and effective code in C #:
///
/// User login verification
/// summary>
/// Username param>
/// Password param>
Public void login (String Userid, String Password)
{
// Database connection string is stored in web.config
String cnnstring = configurationSettings.appsettings ["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);
// Establish and add the 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 ();
// Get the result of the stored procedure returned
String result = paramresult.value.tostring ();
// ... ...
}