gpt4 book ai didi

c# - System.Data.SqlClient.SqlException : Incorrect syntax near '='

转载 作者:太空宇宙 更新时间:2023-11-03 17:40:22 26 4
gpt4 key购买 nike

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

System.Data.SqlClient.SqlException: Incorrect syntax near '='



我已经检查了我的代码,但似乎没有检测到上述错误。请协助。

这是我的代码:
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>");
}

错误显示在
sr = cc.ExecuteReader();

最佳答案

你需要一个空间

 btnString += " WHERE(userName=@name) AND (passWord=@word)";

关于c# - System.Data.SqlClient.SqlException : Incorrect syntax near '=' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28426247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com