繁体   English   中英

创建ASP.net数据库注册连接时出错

[英]Error while creating ASP.net database register connection

我正在尝试使以下错误:System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理

附加信息:关键字“ Table”附近的语法不正确。

    protected void Button_Login_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisterConnectionString"].ConnectionString);
        conn.Open();
        string checkuser = "select count(*) from [Table] where Användarnamn='" + TextBoxAnvändarelogin.Text + "'";
        SqlCommand com = new SqlCommand(checkuser, conn);
        int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
        conn.Close();
        if (temp == 1)
        {
            conn.Open();
            string checkPasswordQuery = "select password from Table where Användarnamn='" + TextBoxAnvändarelogin.Text + "'";
            SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
            string password = passComm.ExecuteScalar().ToString().Replace(" " , ""); // ERROR HERE!
            conn.Close();
            if (password==TextBoxLösenordlogin.Text)
            {
                Session["New"] = TextBoxAnvändarelogin.Text;
                Response.Write("Lösenord är rätt!");
                Response.Redirect("Admin.aspx");
            }
            else
            {
                Response.Write("Lösenord är fel!");
            }
        }
        else
        {
            Response.Write("Användarnamn är inte rätt!");
        }

    }
}

string checkPasswordQuery = "select password from Table where Användarnamn
应该
string checkPasswordQuery = "select password from [Table] where Användarnamn

旁注:使用字符串附加来构建动态sql永远不是一个好习惯。 有关详细信息,请参见Sql注入。 并且不应该使用“表格”作为表格名称

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM