System.Data.SqlClient.SqlException:'='附近的语法不正确

ned*_*eds 1 c# asp.net sql-server-2008

我正在尝试使用a验证登录表单SqlDataReader,但是我收到语法错误

System.Data.SqlClient.SqlException:'='附近的语法不正确

我查看了我的代码,似乎没有检测到上述错误.请协助.

这是我的代码:

string btnString = "SELECT userName, passWord, FacultyId, StudentId FROM LOGIN";
btnString += "WHERE(userName=@name) AND (passWord=@word)";

SqlCommand cc = new SqlCommand();
SqlDataReader sr;

cc.Connection = sqlConn;
cc.CommandType = CommandType.Text;
cc.CommandText = btnString;

cc.Parameters.Add("@name", SqlDbType.Char).Value = txtUserName.Text;
cc.Parameters.Add("@word", SqlDbType.Char, 8).Value = txtPassWord.Text;

sr = cc.ExecuteReader();

if (sr.HasRows == true)
{
    Response.Write("<script>alert('Login is successful!')</script>");
}
Run Code Online (Sandbox Code Playgroud)

错误显示在

sr = cc.ExecuteReader();
Run Code Online (Sandbox Code Playgroud)

Mat*_*ate 8

你需要一个空间

 btnString += " WHERE(userName=@name) AND (passWord=@word)";
Run Code Online (Sandbox Code Playgroud)