语法错误缺失操作员需要在日期之间提供帮助

时间:2015-08-30 01:46:19

标签: c# ms-access

public void FillPresentDays()
{
    con.Open();

    cmd = new OleDbCommand("Select COUNT(*) from AttendanceDatabase  WHERE EmpName =@EmpName and Status =@Status and WHERE Date between @d1 and @d2", con);

    cmd.Parameters.AddWithValue("@EmpName", txtEmpName.Text);
    cmd.Parameters.AddWithValue("@Status", txtP.Text);
    cmd.Parameters.AddWithValue("@d1", dtDate1.Value.Date);
    cmd.Parameters.AddWithValue("@d2", dtDate2.Value.Date);

    cmd.ExecuteNonQuery();
    int count = (int)cmd.ExecuteScalar();
    txtPdays.Text = count.ToString();
    con.Close();
}

非常需要查询帮助

3 个答案:

答案 0 :(得分:1)

同样注释extra where子句尝试下面的

cmd = new OleDbCommand("Select COUNT(*) from AttendanceDatabase  WHERE EmpName =@EmpName and Status =@Status and Date between @d1 and @d2", con)

答案 1 :(得分:1)

您的查询不正确。 WHERE子句只能在单个查询中出现一次。

变化:

Select COUNT(*) from AttendanceDatabase WHERE EmpName =@EmpName and Status =@Status and WHERE Date between @d1 and @d2"

为:

Select COUNT(*) from AttendanceDatabase  WHERE EmpName =@EmpName and Status =@Status and Date between @d1 and @d2"

答案 2 :(得分:0)

and WHERE语法不正确。

您只能有一个WHERE条款。