I keep getting an error that I don't understand:
Must declare the scalar variable "@user"
I'm actually doing a website and I'm using C# ASP.NET and SQL Server. I have a class name Connection
and another one named Query
. And here is the problem
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
{
}
}