为什么在ACCESS中按日期查询总是异常
为什么在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)+'#';
注意 “入站日期”改为“入站时间”
------其他解决方案--------------------
在日期边上加了#,可以了,还是谢谢。
小弟菜鸟
我显示插入了数据:
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)+'#';
注意 “入站日期”改为“入站时间”
------其他解决方案--------------------
在日期边上加了#,可以了,还是谢谢。