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

  • 主题发起人 主题发起人 富翁
  • 开始时间 开始时间

富翁

Unregistered / Unconfirmed
GUEST, unregistred user!
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='+inttostr(Rid)+'));//错误行
open;
end;
如上程序编译可以通过,可是在断点调试中‘错误行‘出错了。而且程序运行
起来以后会出现内存错误。为什么?该怎么改错?
 
这句:
sql.Add('select * from table where (id='''+inttostr(Rid)+''''));//错误行
 
那么多'干什么?我试一下。&&
 
是这样
SQL.Text:='select * from table where id='''+inttostr(Rid)+'''';(id是字符)
或者
SQL.Text:='select * from table where id='+inttostr(Rid);(id是数字)
 
如果使用SQL.Add是这样的
SQL.Add('Select * From Table Where (id='''+IntToStr(Rid)+''')');(id是字符)
SQL.Add('Select * From Table Where (id='+IntToStr(Rid)+')');(id是数字)
 
sql.Add('select * from table where id='+inttostr(Rid))
 
还有一点疑问?
最好不用ID作为字段名,那东西很可能是系统关键字,如果是的话,会很麻烦的。
 
好像有戏!!
 
那就好了,我走了。[:D][:D][:D][:D][:D][:D]
 
明天可能还得麻烦你.thanks
 
来晚了~yzhshi是权威呀~~:)
yzhshi 大侠能不能再说说 TAdoQuery为什么没有PararByName属性呀?
To 富翁
在DELPHI中写SQL语句时,用两个《‘》来代表SQL语句中的一个《’》
 
嘿嘿,我又回来了,刚才同事说稍微晚一会回去,我又能逛半小时了!
完颜康,谁说没有ParamByName属性,实验一下呀。。。
ADOQuery1.Parameters.ParamByName('aa').Value
 
yzhshi:
还是不行啊!可是我做了一个测试程序却没有出现这样的错误。为什么?

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
i:=strtoint(edit1.text);
gettimes(i);
end;

procedure TForm1.gettimes(Rid: integer);
begin
with adoquery1 do
begin
close;
sql.Clear;
// parameters.ParamByName('id').asstring:=edit1.text;
sql.Add('select id,subject from letters where (id='+inttostr(Rid)+')');
open;
end;

end;
 
出什么错呀?
 
断点调试的时候这句前头不是对号。
 
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='+inttostr(Rid)+'));//错误行
sql.Add('select * from table where (id='+ #39 + inttostr(Rid) + #39 +')');
open;
end;
 
每人回答吗?
 
如果id是整数类型,则
sql.Add('select * from table where id='''+inttostr(rid)+'''');
 
我的delphi6启动不了了,哦。对了,最近刚刚安装了win2000(98,2000双操作)。原来一直是
在98下面。我还用重新在2000下安装delphi6吗?
 
sql.Add('select * from table where (id='+#39+inttostr(Rid)+#39+')');
ok!
 
后退
顶部