样把变量传递给adoquery1.sql.add('.......')语句

cutedelphigirl 2003-08-19 06:30:10
各位前辈,我写的下面几行老出错:
var
s:string
begin
s:=edit1.text;
adoquery1.sql.add('select * from aaa where name=s');
adoquery1.open;
...
end;
我想把s传递给SQL,怎么老出错?
谢谢!
...全文
30 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
nhdj 2003-08-22
  • 打赏
  • 举报
回复
晕,就2分阿?
w7755 2003-08-19
  • 打赏
  • 举报
回复
用franne(沖天笑) 的办法比较好
windwather 2003-08-19
  • 打赏
  • 举报
回复
With Adoquery1 Do
Begin
If Acitve Then Close;
Sql.Clear;
Sql.Add(''select * from aaa where name=:name');
Parameters[0].Value:=Edit1.Text;
If Not Prepared Then Prepared;
Open;
End;

michaelpeng7799 2003-08-19
  • 打赏
  • 举报
回复
使用参数是不,不容易出错。
如果只是字符串变量相加,有时在大堆引号会很烦的,容易出错。
sduzjw 2003-08-19
  • 打赏
  • 举报
回复
應該可以解決
franne 2003-08-19
  • 打赏
  • 举报
回复
又看见你的帖了,你经常上CSDN吗?呵呵
franne 2003-08-19
  • 打赏
  • 举报
回复
var
s:string
begin
s:=edit1.text;
adoquery1.active:=false;
adoquery1.sql.clear;
adoquery1.sql.add('select * from aaa where name=:s');
adoquery1.parameters.parambyname('s')=s;
adoquery1.active:=true;
end;
试试看,
yckxzjj 2003-08-19
  • 打赏
  • 举报
回复
借用楼上两位兄弟的语句:

adoquery1.sql.add('select * from aaa where name=' + QuotedStr(s) );


var
s:string
begin
s:=edit1.text;
adoquery1.sql.add('select * from aaa where name='+s);
adoquery1.open;
...
end;
S包在''中就是S,而不是你附值的EDIT.TEXT
Spqk005 2003-08-19
  • 打赏
  • 举报
回复
ysycrazy(风中狂) ( 写错了

应该是
var
s:string
begin
s:=edit1.text;
adoquery1.sql.text:='select * from aaa where name=:s';
adoquery1.parameters.parambyname('s').value:=s;
adoquery1.open;
...
end;
nhdj 2003-08-19
  • 打赏
  • 举报
回复
推荐你还是用参数吧,用参数感觉比较好,绝对准确
var
s:string
begin
s:=edit1.text;
adoquery1.sql.clear;
adoquery1.sql.add('select * from aaa where name=:lsname');
adoquery1.parameters.parambyname('lsname').value:=s
adoquery1.open;
end;

to:ysycrazy(风中狂) ,你的修改为:
adoquery1.parameters.parambyname('s').value:=s;
cutedelphigirl 2003-08-19
  • 打赏
  • 举报
回复
那个比较准确一点?
ysycrazy 2003-08-19
  • 打赏
  • 举报
回复
各位前辈,我写的下面几行老出错:
var
s:string
begin
s:=edit1.text;
adoquery1.sql.text:='select * from aaa where name=:s';
adoquery1.parambyname('s').value:=s;
adoquery1.open;
...
end;


Spqk005 2003-08-19
  • 打赏
  • 举报
回复
var
s:string
begin
s:=edit1.text;
adoquery1.sql.add('select * from aaa where name='+s);
adoquery1.open;
...
end;
S包在''中就是S,而不是你附值的EDIT.TEXT
DWGZ 2003-08-19
  • 打赏
  • 举报
回复
adoquery1.sql.add('select * from aaa where name=' + QuotedStr(s) );

5,388

社区成员

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

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