关于Adoquery中的查询语句。在线等待!

zhaobaoxian 2003-08-16 10:46:04
本人要使用select 语句中的参数查询:
具体如下
Select * from Table1 where ID= str
其中str 是传过来的参数,
请问str如何设置?或者查询语言如何改写?
...全文
31 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnhgj 2003-08-16
  • 打赏
  • 举报
回复
同意!
如果是变量那么就
ADOQuery1.Sql.Clear;
ADOQuery1.Sql.Add('Select * from Table1 where ID=' + str);
ADOQuery1.Open;
zousoft 2003-08-16
  • 打赏
  • 举报
回复
或是
ADOQuery1.Sql.Clear;
ADOQuery1.Sql.Add.Format('Select * from Table1 where ID=%s', [str]);
ADOQuery1.Prepare;
ADOQuery1.Open;
zhaobaoxian 2003-08-16
  • 打赏
  • 举报
回复
不是这样的
比如说Form2使用到了这个sql查询语句。但是那个参数要从Form1中的Edit1中获取。谢谢
刚才的TOMVVLD的方法不行!
lwn19820725 2003-08-16
  • 打赏
  • 举报
回复
ADOQuery1.Sql.Clear;
ADOQuery1.Sql.Add('Select * from Table1 where ID=:str');
ADOQuery1.Parameters.ParamByName('str').Value:=参数;
ADOQuery1.Open;
zhp97 2003-08-16
  • 打赏
  • 举报
回复
呵呵,同意楼上的,看来我手脚还是不够快
TOMWLD 2003-08-16
  • 打赏
  • 举报
回复
ADOQuery1.Sql.Clear;
ADOQuery1.Sql.Add(Select * from Table1 where ID=:str);
ADOQuery1.Parameters.ParamByName('str').Value:='fdf';
ADOQuery1.Open;
lvshao 2003-08-16
  • 打赏
  • 举报
回复
强烈反对那样的书写格式,应该为
var
sSQL : string;
begin

with Form2.ADOQuery1 do
begin
Close;
sql.clear;
sSQL := 'select * from table1'
sSQL := sSQL + ' where ID='+''''+str+''''
sql.add( sSQL );
Open;
end;
只是看那种写法不是特别容易阅读,所以提醒一下,大家见笑!
zhaobaoxian 2003-08-16
  • 打赏
  • 举报
回复
还是不行!
不过我已经解决了
在Form1的Buttom1窗口了加入
uses Form2;
with Form2.ADOQuery1 do
begin
Close;
Form5.ADOQuery1.SQL.clear;
Form5.ADOQuery1.SQL.add('select * from table1');
Form5.ADOQuery1.SQL.add(' where ID='+''''+str+'''');
Open;
end;
谢谢各位参加!
siyuan_qian 2003-08-16
  • 打赏
  • 举报
回复
ADOQuery1.sql.clear;
ADOQuery1.sql.add('select * from table where ID=: ss');
ADOQuery1.Parameters.ParamByName('ss').Value:=form1.edit1.text;(从form1传过来的参数)
ADOQuery1.open;
你看这样行不?

zhaobaoxian 2003-08-16
  • 打赏
  • 举报
回复
各位大虾还是不行呀,求救了!!!
是变量要从Form1传过来的亚!(在Form2里面的具体sql写法)
,谢谢

2,495

社区成员

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

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