2015-08-30 54 views
0
public void FillPresentDays() 
{ 
    con.Open(); 

    cmd = new OleDbCommand("Select COUNT(*) from AttendanceDatabase WHERE EmpName [email protected] and Status [email protected] 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(); 
} 

之间急需帮助查询语法错误缺少运算需要帮助的日期

+0

尝试把一个空间后,在查询你的'='的迹象。 –

+0

我认为两个where子句是问题 –

+0

仍然不工作:( –

回答

1

说相同的评论额外的where子句尝试以下

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

and WHERE是不正确的语法。

您只能有一个WHERE子句。

+0

如何搜索两个日期之间的当前日子总数? –

1

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

变化:

Select COUNT(*) from AttendanceDatabase WHERE EmpName [email protected] and Status [email protected] and WHERE Date between @d1 and @d2" 

到:

Select COUNT(*) from AttendanceDatabase WHERE EmpName [email protected] and Status [email protected] and Date between @d1 and @d2" 
+0

谢谢!我已经工作了。 –