我正在尝试使用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)