我試圖用SqlDataReader
驗證登錄表單,但我得到一個語法錯誤System.Data.SqlClient.SqlException:附近有語法錯誤「=」
System.Data.SqlClient.SqlException:不正確的語法'='
我檢查了我的代碼,似乎沒有檢測到上述錯誤。請協助。
這是我的代碼:
string btnString = "SELECT userName, passWord, FacultyId, StudentId FROM LOGIN";
btnString += "WHERE([email protected]) AND ([email protected])";
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();
謝謝,這個工作 – neds 2015-02-10 07:56:31
不客氣。檢查@Konstantin Spirin答案中的多行字符串 – Mate 2015-02-10 08:02:27