我该怎么做?我使用Windows窗体和标签。
如何计算带有条件的表中的行数? C#和MS Access。
我的代码:
string CONECTION = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = SRC\\DATA\\DBACCSES2005.mdb";
string Query = "Select count(*) FROM SALES WHERE DATE="+DateTime.Today;
OleDbConnection con = new OleDbConnection(CONECTION);
OleDbCommand cmd = new OleDbCommand(Query, con);
con.Open();
int TOTALSALES = (Int32)cmd.ExecuteScalar();
SALES.TEXT = totalid.ToString();
CON.CLOSE();
答案 0 :(得分:0)
对日期值使用正确的字符串表达式格式:
string Query = "Select Count(*) FROM SALES WHERE [DATE] = #" + DateTime.Today.ToString("yyyy'/'MM'/'dd") +"#";
或更简单地,使用Access功能:
string Query = "Select Count(*) FROM SALES WHERE [DATE] = Date()";