Use of stored procedures in Asp.net

Source: Internet
Author: User

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> ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.