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