adoquery查询中的sql语句错误? (200分)

  • 主题发起人 主题发起人 富翁
  • 开始时间 开始时间
谢谢各位的热情帮助,所有的方法都试了,还是不行。我的问题可能比较复杂,我发现d6的
编辑器好像有点毛病。会出现许多莫名其妙的错误。我还是重新安装一下系统看看吧!关于
那个2000下d6的使用问题有人能给解答一下吗?谢谢。
 
?各位都干什么呢?唉!没人回答了,明天结束我的贴子。
 
如果id是数值型
sql.Add('select * from table where (id='+inttostr(Rid)+')');
如果id是字符型
sql.Add('select * from table where (id='''+inttostr(Rid)+''')');
 
我没有安装D6,也没有使用2000,呵呵,没戏了。
 
来晚了!
flysand同志所言既是
 
你这样写肯定有问题的,可以这样写:
sql.Add('select * from table where id='+inttostr(Rid));
在SQL语句中,如果是id字段数字,不需要加引号的。如果id是字符串,就应该这样写:
sql.Add('select * from table where id='+#39+Rid+#39);
如果id是日期,就应该这样写:
sql.Add('select * from table where id='+'#'+DateTimeToStr(RID)+'#');
就是用两个#号把日期值括起来。
 
我看有必要好好总结一下sql语句中这些写法的一些规范了。看看以前的贴子也是有许多相同的问题
。以后还会有,不同的数据库,不同的语言规范,不同的人,不同的习惯,导致了不同的错误。
 
sql.Add('select * from table where (id='+inttostr(Rid)+'))
改为:
sql.Add('select * from table where id='+#39+inttostr(Rid)+#39);
 
procedure Tmk.Getname(Rid: integer; var name:string);
begin
with ado1 do
begin
if active then close;
sql.Clear;
sql.Add('select * from table where id='+quotedstr(inttostr(Rid))+')';//错误行
open;
end;
 
我看这个问题就到此为止了,谢谢各位的回答,虽然我的问题并没有真正解决,但我还是要谢谢
大家。尤其感谢yzhshi.
 
后退
顶部