sql 出错

xztslsz 2005-04-21 11:13:34
我用编辑框输入号码,在回车后想在DBgrid中显示对应的记录,用了Query,使用的Access数据库,运行时出示错误:
project project1.exe raised exception class EDBEngineError with message 'General SQL error.[Mirosoft][ODBC Microsoft Access Driver]标准表达式中数据类型不匹配。'process stopped
代码如下:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var s:string;
begin
s:=edit1.text;
if key=13 then
begin
with Query1 do
begin
close;

SQL.clear;

SQL.add('select * from ydy where hm='+s);

open;

end;
end;

end;
...全文
114 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxh850619 2005-04-21
  • 打赏
  • 举报
回复
select * from ydy where hm="'+s+'"应该可以吧
sunmingdong 2005-04-21
  • 打赏
  • 举报
回复
如果hm是字符串或日期的话,需要加引号

如'select * from ydy where hm='''+s+''''
或'select * from ydy where hm='+quotedstr(s)
或'select * from ydy where hm='+#39+s+#39

建议用第二种,会把s中的单引号替换为''
postren 2005-04-21
  • 打赏
  • 举报
回复
Access 应该可以用双引号的

SQL.add('select * from ydy where hm="'+s + '"');
jinjazz 2005-04-21
  • 打赏
  • 举报
回复
'select * from ydy where hm='''+s+''''
xztslsz 2005-04-21
  • 打赏
  • 举报
回复
谢谢了

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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