I'm trying to query a table, but I get an error when I execute it, it only happens when I add "Where Sdate=@date and Staffid=@mobile" if I don't give a condition it works fine, here is the code
private void button1_Click(object sender, EventArgs e)
{
getsum();
}
public void getsum()
{
string query = @"select SUM(SQuantity) AS Total FROM Sales where Sdate=@date AND Staffid=@mobile";
using (var conn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data source=|DataDirectory|\\crepeDB.accdb;"))
using (var cmd = new System.Data.OleDb.OleDbCommand(query, conn))
{
cmd.Parameters.Add("@mobile", System.Data.OleDb.OleDbType.VarChar).Value = '1';
cmd.Parameters.Add("@date", System.Data.OleDb.OleDbType.VarChar).Value = dateTimePicker1.Value.Date;
conn.Open();
using (var rdr = cmd.ExecuteReader())
{
if (rdr.Read())
{
textBox1.Text = rdr["Total"].ToString();
}
rdr.Close();
}
}
}
Hope anyone can help me fix this