读书人

为什么在ACCESS中按日期查询总是异常

发布时间: 2012-12-15 15:16:03 作者: rapoo

为什么在ACCESS中按日期查询总是错误?
小弟菜鸟
我显示插入了数据:
sLan:='Insert into mjkc (ID,制令,总颗数,入站时间) VALUES ('''+id+''','''+lotno+''','+keshu+','+'#'+datetostr(now)+'#'+')';
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(slan);
ADOQuery1.ExecSQL;

然后按日期去查询:
slan:='select *from mjkc where 入站日期='+'#'+datetostr(now)+'#';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.add(slan);
ADOQuery1.Open;

提示 参数 入站时间没有默认值 错误。。。。

不知道怎么回事,哪个大侠教教我?
[最优解释]
//给个例子你吧
FSQLText = ' select SAMPLE_ID as ybbh, ITEM as xmdh, '
+ ' RESULT as xmcdz from SAMPLE_ITEM_TEST_RESULT '
+ ' where TIME >= :BTIME'
+ ' and TIME < :ETIME order by SAMPLE_ID desc';
with FAdoQuery do
try
Close;
SQL.Text := FSQLText;
Parameters.ParamByName('BTIME').Value := dBDate;
Parameters.ParamByName('ETIME').Value := dEDate;
Open;
Result := True;
except
On E: Exception do
begin
Result := False;
StateMsg := '查询数据失败: ' + E.Message;
end;
end;
[其他解释]
你用参数形式传递, 从来没有见错过
[其他解释]
参数形式?怎么写?
[其他解释]
我试试看。。
[其他解释]
slan:='select *from mjkc where 入站日期='+'#'+datetostr(now)+'#';

注意 “入站日期”改为“入站时间”
[其他解释]
在日期边上加了#,可以了,还是谢谢。

读书人网 >.NET

热点推荐