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
/*
......
*/
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 ();
//......
}