我不斷收到,我不明白的錯誤:必須聲明標量變量「@user」
必須聲明標量變量「@user」
我實際上做一個網站,我正在使用C#ASP.NET和SQL Server。我有一個班級名稱Connection
,另一個名爲Query
。這裏是問題
public class Query
{
public int ValidateLogin(string userID, string password)
{
string query = "Select * From tblLogin where UserID = @user and Password = @paswd";
Connection objConn = new Connection();
DataTable dtLogin = objConn.GetDataFromDB(query);
int result = 0;
if (dtLogin.Rows.Count > 0)
{
result = 1;
}
return result;
}
public class Connection
{
string conn = ConfigurationManager.ConnectionStrings["DBConn"].ToString();
public DataTable GetDataFromDB(string query)
{
SqlConnection myConn = new SqlConnection(conn);
myConn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = myConn.CreateCommand();
da.SelectCommand.CommandText = query;
DataTable dt = new DataTable();
da.Fill(dt);
da.Dispose();
myConn.Close();
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_login_Click(object sender, EventArgs e)
{
int result = 0;
Query q = new Query();
result = q.ValidateLogin(txt_userID.Text, txt_password.Text);
if (result == 1)
{
Response.Redirect("~/Performance Appraisal Form.aspx");
}
else
{
}
}
您要使用的參數與你的查詢,但你是不是將它們連接到命令的任何地方 – Habib
@Habib後它的答案。 –