Web first session SQL database connection query

Source: Internet
Author: User
Tags connectionstrings

1. Database connection Statement

<connectionStrings>          <add name="yhotel" connectionstring= " Database=yhotel; Server=.;i Ntegrated Security=false; Uid=sa; Password=zts; "   Providername="System.Data.SqlClient" /></connectionstrings>

where name= "Yhotel" as far as the database with the same name, and the system is the node name to obtain the connection string, is obtained through the ConfigurationManager method, generally written in the Web. config file

2. Click the Clear button to clear the user name and password

 /// <SUMMARY>  ///  /// </summary>  /// <param name= " Sender "></PARAM>  /// < param name= "E" ></PARAM>  void  Btnclear_click (object   sender, EventArgs e) {txtusername.text  =  ;        Txtpwd.text  =  

3, click the login button to get the user name and password, the use of SQL statements to the database query, return a userid, judge if the userid is not NULL, then the authentication succeeds, if NULL, does not pass

        /// <summary>        ///Login Button/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        protected voidBtnlogin_click (Objectsender, EventArgs e) {            stringUsername =TxtUserName.Text.Trim (); stringPWD =TxtPwd.Text.Trim (); if(string. IsNullOrEmpty (username) | |string. IsNullOrEmpty (pwd)) {Response.Write ("<script>alert (' User name or password cannot be null ');</script>"); }            Else             {                stringStrcon = configurationmanager.connectionstrings["Yhotel"]. ToString ();//Like into a phone number               using(SqlConnection con =NewSqlConnection (Strcon))//Like phone{con. Open ();//established a connection with the database                stringstrSQL =string. Format ("Select USERID from userlist where Username= ' {0} ' and pwd= ' {1} '", USERNAME,PWD); SqlCommand cmd=NewSqlCommand (strSQL, con); using(SqlDataReader read =cmd. ExecuteReader ()) {if(read. Read ()) {Response.Write ("<script>alert (' Landing success ');</script>"); }                Else{Response.Write ("<script>alert (' Username or password error ');</script>"); }                }               }            }        }

Web first session SQL database connection query

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.