我不断收到,我不明白的错误:必须声明标量变量“@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后它的答案。 –