读书人

access 关于时间查询,该怎么解决

发布时间: 2012-04-27 11:57:44 作者: rapoo

access 关于时间查询
1、如何进行指定时间查询?cpuhistory表中有begintime项类型为日期。 程序如下,报错提示:表达式中数据类型不匹配
AnsiString str="2012-3-24 14:59:47";
sqlstr="select * from cpuhistory where begintime='"+str+"'";
ADOQuery1->Connection=ADOConnection1;
ADOQuery1->Active=false;
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add(sqlstr);
ADOQuery1->Active=true;
换成sqlstr="select * from cpuhistory where begintime=#"+str+"#";结果一样,该怎么改?
2、cpuhistory表中begintime字段如何与当前时间比较?我想取得昨天或者今天的数据。

[解决办法]
sqlstr="select * from cpuhistory where begintime <=begintime";
ADOQuery1->SQL->Add(sqlstr);
ADOQuery1->Parameters->ParamByName( "begintime")->Value=str;
ADOQuery1->Active=true;

改为

sqlstr="select * from cpuhistory where begintime <=:begintime";
ADOQuery1->SQL->Add(sqlstr);
ADOQuery1->Parameters->ParamByName( "begintime")->Value=str;
ADOQuery1->Active=true;

读书人网 >C++ Builder

热点推荐