我有兩個查詢..我想要做的是如果登錄控件在第一個查詢表中找到用戶名和密碼,將其重定向到賣家頁面。如果它發現第二個查詢表中的un和pw然後將其重定向到經銷商頁面。我怎樣才能做到這一點?因爲它只檢查第一個查詢。根據執行的查詢,登錄控制重定向到不同的頁面
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
var conString = ConfigurationManager.ConnectionStrings["CONSTRING"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string user = Login1.UserName;
string pass = Login1.Password;
con.Open();
SqlCommand cmd1 = new SqlCommand("select username, password, status from login where username = '" + user + "' and password = '" + pass + "' and status = 1", con);
string CurrentName;
CurrentName = (string)cmd1.ExecuteScalar();
if (CurrentName != null)
{
Session.Timeout = 1;
Session["un"] = Login1.UserName;
Response.Redirect("sellerlogin.aspx?un=" + Login1.UserName);
}
SqlCommand cmd2 = new SqlCommand("select username, password, status from dealer where username = '" + user + "' and password = '" + pass + "' ", con);
string CurrentNam;
CurrentNam = (string)cmd2.ExecuteScalar();
if (CurrentNam != null)
{
Session.Timeout = 1;
Response.Redirect("dealerlogin.aspx?un="+ Login1.UserName);
}
什麼意思 「只檢查第一個查詢」?你用過調試器嗎?始終使用參數化查詢而不是字符串連接! –