各位大哥大姐帮帮忙!!!!在线等。。。。。。。

ndd987 2005-09-30 03:45:35
access数据库中表名是:表1。有一个字段名是:时间。字段的类型是:‘时间日期’型的。
我用sql语句查询:'select * from 表1 where 时间='''+datetostr(datetimepicker1.date)+''''
就报错说:“标准表达式中的数据类型不匹配”
这是怎么回事啊?
...全文
75 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
winxkm 2005-09-30
  • 打赏
  • 举报
回复
习惯使用参数parameters的做法值得欣赏, 如果你一定坚持你的做法,
在你的SQL语句中where部分的判断应该这样写
adoquery1.SQL.Add('select * from 表1 where 时间='+datetostr(datetimepicker5.Date));
gxgyj 2005-09-30
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
tempstr:string;
begin
tempstr:='select * from 表1 where 时间=:temp1';
with ADOQuery1 do begin
close;
sql.Add(tempstr);
Parameters.ParamByName('temp1').Value:=FormatDateTime('yyyy-mm-dd',DateTimePicker1.DateTime);
Open;
end;//end adoquery1
end;

////////////////这样是可以的...
ndd987 2005-09-30
  • 打赏
  • 举报
回复
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 表1 where 时间='''+datetostr(datetimepicker5.Date)+'''');
adoquery1.Open;
错误信息:“标准表达式中的数据类型不匹配”
gxgyj 2005-09-30
  • 打赏
  • 举报
回复
楼主把你的代码和错误信息贴上来看看...
ndd987 2005-09-30
  • 打赏
  • 举报
回复
不行啊,以上两位的我都试过了,还是报错,怎么办啊???
aiirii 2005-09-30
  • 打赏
  • 举报
回复
where 时间='#'+datetostr(datetimepicker1.date)+'#'
gxgyj 2005-09-30
  • 打赏
  • 举报
回复
tempstr:='select * from 表1 where 时间=:temp1';
sql.Add(tempstr);
Parameters.ParamByName('temp1').Value:=FormatDateTime('yyyy-mm-dd',DateTimePicker2.DateTime);
Open;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧