C# System.Data.SqlClient.SqlException:';靠近'的语法不正确;userX';

C# System.Data.SqlClient.SqlException:';靠近'的语法不正确;userX';,c#,sql,asp.net,webforms,C#,Sql,Asp.net,Webforms,我试图创建一个登录页面时,我试图登录它给我这个错误 不知道怎么修 有什么想法吗 protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].ConnectionString); conn.O

我试图创建一个登录页面时,我试图登录它给我这个错误

不知道怎么修

有什么想法吗

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].ConnectionString);
        conn.Open();
        string checkuser = " select count(*) from NewLogins where username = '" + TextBoxUsername.Text + "' and Password = '" + TextBoxPassword.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 NewLogins where username'" + TextBoxUsername.Text + "'";
            SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
            string password = passComm.ExecuteScalar().ToString().Replace(" ", "");
            conn.Close();
            if (password == TextBoxPassword.Text)
            {
                Session["New"] = TextBoxUsername.Text;
                Response.Write("Password is correct");
                Response.Redirect("Manager.aspx");
            }
            else
            {
                Response.Write("Password is not correct");
            }
        }
        else
        {
            Response.Write("Username is not correct");
        }

    }
这是我得到的错误:


System.Data.SqlClient.SqlException:“userX”附近的语法不正确

在这一行上,字符串password=passComm.ExecuteScalar().ToString().Replace(“,”)


“=”运算符是按@Igor Tandetnik所述添加的,您没有指定您遇到的错误。System.Data.SqlClient.SqlException:“userX”附近的语法不正确
其中username=
。查询缺少比较运算符。
string checkPasswordQuery = "select password from NewLogins where username='" + TextBoxUsername.Text + "'";