aspx裡面加2個textbox一個button
.cs檔案裡面程式碼我的伺服器是.
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringconnString=Convert.ToString(ConfigurationManager.ConnectionStrings["sqlconn"]);
SqlConnectionconn=newSqlConnection(connString);//建立資料庫連結
conn.Open();
stringstrsql="select*fromstuentwhereStuName=""+TextBox1.Text+""andStupassword=""+TextBox2.Text+""";
SqlCommandcmd=newSqlCommand(strsql,conn);
SqlDataReaderdr=cmd.ExecuteReader();
if(dr.Read())
Session["StuName"]=dr["StuName"];
Session["Stupassword"]=dr["Stupassword"];
if(TextBox1.Text==Session["StuName"].ToString()&&TextBox2.Text==Session["Stupassword"].ToString())
Response.Redirect("Default2.aspx");
}
else
Label1.Text="登陸失敗,請檢測輸入!";
web.config
aspx裡面加2個textbox一個button
.cs檔案裡面程式碼我的伺服器是.
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringconnString=Convert.ToString(ConfigurationManager.ConnectionStrings["sqlconn"]);
SqlConnectionconn=newSqlConnection(connString);//建立資料庫連結
conn.Open();
stringstrsql="select*fromstuentwhereStuName=""+TextBox1.Text+""andStupassword=""+TextBox2.Text+""";
SqlCommandcmd=newSqlCommand(strsql,conn);
SqlDataReaderdr=cmd.ExecuteReader();
if(dr.Read())
{
Session["StuName"]=dr["StuName"];
Session["Stupassword"]=dr["Stupassword"];
if(TextBox1.Text==Session["StuName"].ToString()&&TextBox2.Text==Session["Stupassword"].ToString())
{
Response.Redirect("Default2.aspx");
}
}
else
{
Label1.Text="登陸失敗,請檢測輸入!";
}
}
web.config