一个删除ACCESS奇怪的问题!

yangzong20 2011-05-03 05:34:37
我用ADOQuery来操作ACCESS但我删除表记录的的时候它提示"语法错误(操作符丢失)在查询表达式"!

try
ADOQuery6.Close;
ADOQuery6.SQL.Clear;
sql:='delete from Basic_information where id='+trim(ClientDataSet1id.Text);
ADOQuery6.SQL.Add('delete Basic_information where id='+trim(ClientDataSet1id.Text));
ADOQuery6.ExecSQL;
showmessage('删除成功!');
except
showmessage('删除失败!');
exit;
end;

我截取了sql字符串直接在access里运行时正常的呀,是不是要设置什么地方?麻烦各位大哥帮看看
...全文
78 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
浩南_哥 2011-05-03
  • 打赏
  • 举报
回复
你最好是用sql.add(strsql)这样添加,在调试下strsql有可能就是语句的问题,因为从你贴的代码上面我是没看出什么问题。
yangzong20 2011-05-03
  • 打赏
  • 举报
回复
to 各位大哥

1.ADOQuery6.SQL.Add('delete from Basic_information where id='+trim(ClientDataSet1id.Text));这是我写上来的时候疏忽忘记写了,程序里是有的。


2.我的id是数字型呀,不是字符型呀,所以where id=在这不能加引号呀

麻烦各位大哥在帮看看,我断点调试截取sql字符串把他放到access里运行是正常的呀,为什么放到ADOQuery里运行就会提示"语法错误(操作符丢失)在查询表达式"!我觉得关键是(操作符丢失)是不是要设置ADOQuery的什么属性呀?

浩南_哥 2011-05-03
  • 打赏
  • 举报
回复
ADOQuery6.SQL.Add('delete from Basic_information where id='+trim(ClientDataSet1id.Text));
basic_information前少个from
haochin 2011-05-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jankercsdn 的回复:]
sql:='delete from Basic_information where id='''+trim(ClientDataSet1id.Text)+'''';
ADOQuery6.SQL.Add(sql);
[/Quote]

+1

sql:='delete from Basic_information where [id]='''+trim(ClientDataSet1id.Text)+'''';
ADOQuery6.SQL.Add(sql);
这个会更好些。
看那山瞧那水 2011-05-03
  • 打赏
  • 举报
回复
sql:='delete from Basic_information where id='''+trim(ClientDataSet1id.Text)+'''';
ADOQuery6.SQL.Add(sql);
yangzong20 2011-05-03
  • 打赏
  • 举报
回复
麻烦大哥们帮看看,小弟谢谢了

5,386

社区成员

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

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