Use of stored procedures in Asp.net
Note: The direction attribute of parameters: gets or sets a value indicating whether the parameter can be input, output, bidirectional, or stored procedure return parameters. Its value range is parameterdirection Enumeration type.
Enumerated values and descriptions
| Enumeration name |
Description |
| Input |
The parameter is an input parameter. |
| InputOutput |
Parameters are both input and output parameters. |
| Output |
The parameter is an output parameter. |
| Returnvalue |
Return Value |
Protected void button#click (Object sender, eventargs e) {If (textbox1.text = request. cookies ["imagev"]. value) // use the verification code {Conn. open (); sqlcommand cmd = new sqlcommand ("login", Conn); cmd. commandtype = commandtype. storedprocedure; // commandtype attribute setting: The Stored Procedure CMD is used here. parameters. add ("@ user", sqldbtype. varchar, 20); cmd. parameters. add ("@ PWD", sqldbtype. varchar, 20); cmd. parameters ["@ user"]. value = Username. Text; cmd. parameters ["@ PWD"]. value = formsauthentication. hashpasswordforstoringinconfigfile (this. userpwd. text, "MD5"); cmd. parameters. add ("@ return", sqldbtype. bit, 2); cmd. parameters ["@ return"]. direction = parameterdirection. output; // note the case sensitivity of output. cmd. executenonquery (); // you must first execute the command to obtain the @ return value Conn. close (); bool flag = convert. toboolean (CMD. parameters ["@ return"]. value); // If (FLAG) {response. cook IES ["admincookies"]. value = username. text; response. redirect ("index.html");} else // response. write ("Incorrect username or password"); response. write ("<script language = 'javascript '> alert ('login failed! Incorrect username or password !! '); Location = 'loginproc. aspx' </SCRIPT> ");} else {response. Write (" <script language = 'javascript '> alert ('login failed! Incorrect verification code !! '); Location = 'loginproc. aspx' </SCRIPT> ");}}