A simple example is as follows:
1. Create a stored procedure for user authentication ):
Create procedure checkuser
(
@ Userid char (20 ),
@ Userpsw char (20)
)
As
If exists (select * From tb_userinfo where rtrim (userid) = @ userid and rtrim (userpsw) = @ userpsw)
Return 1
Else
Return 0
2. Asp.net executionCode:
// Connect to the database
String mystr = configurationmanager. etettings ["connectionstring"]. tostring ();
Sqlconnection myconn = new sqlconnection (mystr );
Myconn. open ();
// Create a sqlcommand object
Sqlcommand cmd = new sqlcommand ("Checkuser", Myconn );
Cmd. commandtype = commandtype. storedprocedure;
// Add Parameters
Sqlparameter userid = cmd. Parameters. Add ("@ userid", sqldbtype. Char );
Sqlparameter userpsw = cmd. Parameters. Add ("@ userpsw", sqldbtype. Char );
Sqlparameter returnvalue = cmd. Parameters. Add ("@ returnvalue", sqldbtype. INT );
// Specify whether the parameter can be input, output, or returnvalue)
Userid. Direction = parameterdirection. input;
Userpsw. Direction = parameterdirection. input;
Returnvalue. Direction = parameterdirection. returnvalue;
// Assign a value to the parameter passed to the stored procedure
Userid. value = tbusername. Text. Trim ();
Userpsw. value = tbpsw. Text. Trim ();
// Execute the SQL stored procedure
Cmd. executenonquery ();
// obtain and determine the return value
If (INT) returnvalue. value == 1)
{< br> session ["user"] = tbusername. text. trim ();
response. write ("current user:" + session ["user"]);
}< br> else
{< br> response. write ("the user does not exist! ");
}