Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据执行的查询重定向到不同页面的登录控件_C#_Sql - Fatal编程技术网

C# 根据执行的查询重定向到不同页面的登录控件

C# 根据执行的查询重定向到不同页面的登录控件,c#,sql,C#,Sql,我有两个问题。。我想做的是,如果登录控件在第一个查询表中找到用户名和密码,请将其重定向到卖家页面。。如果在第二个查询表中找到un和pw,则将其重定向到经销商页面。我该怎么做?因为它只检查第一个查询 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { var conString = ConfigurationManager.ConnectionStrings["CONST

我有两个问题。。我想做的是,如果登录控件在第一个查询表中找到用户名和密码,请将其重定向到卖家页面。。如果在第二个查询表中找到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);
        }
尝试使用:

Response.End();
return;
使用您的代码:

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);
        Response.End();
        return;
    }
    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);
        Response.End();
        return;
    }

什么意思是“它只检查第一个查询”?你用过调试器吗?始终使用参数化查询而不是字符串连接!这解决了什么问题?OP说它“只检查第一个查询”genius:o非常感谢:D@Samsam-我很乐意帮助你!请选择我的答案作为正确答案,并投票表决。非常感谢。