本人要使用select 语句中的参数查询:
具体如下
Select * from Table1 where  ID= str
其中str 是传过来的参数,
请问str如何设置?或者查询语言如何改写?

解决方案 »

  1.   

    ADOQuery1.Sql.Clear;
    ADOQuery1.Sql.Add(Select * from Table1 where  ID=:str);
    ADOQuery1.Parameters.ParamByName('str').Value:='fdf';
    ADOQuery1.Open;
      

  2.   

    ADOQuery1.Sql.Clear;
    ADOQuery1.Sql.Add('Select * from Table1 where  ID=:str');
    ADOQuery1.Parameters.ParamByName('str').Value:=参数;
    ADOQuery1.Open;
      

  3.   

    不是这样的
    比如说Form2使用到了这个sql查询语句。但是那个参数要从Form1中的Edit1中获取。谢谢
    刚才的TOMVVLD的方法不行!
      

  4.   

    或是
    ADOQuery1.Sql.Clear;
    ADOQuery1.Sql.Add.Format('Select * from Table1 where  ID=%s', [str]);
    ADOQuery1.Prepare;
    ADOQuery1.Open;
      

  5.   

    同意!
    如果是变量那么就
    ADOQuery1.Sql.Clear;
    ADOQuery1.Sql.Add('Select * from Table1 where  ID=' + str);
    ADOQuery1.Open;
      

  6.   

    各位大虾还是不行呀,求救了!!!
    是变量要从Form1传过来的亚!(在Form2里面的具体sql写法)
    ,谢谢
      

  7.   

    ADOQuery1.sql.clear;
    ADOQuery1.sql.add('select * from table where ID=: ss'); 
    ADOQuery1.Parameters.ParamByName('ss').Value:=form1.edit1.text;(从form1传过来的参数)
    ADOQuery1.open;
    你看这样行不?
      

  8.   

    还是不行!
    不过我已经解决了
    在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;
    谢谢各位参加!
      

  9.   

    强烈反对那样的书写格式,应该为
    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;
    只是看那种写法不是特别容易阅读,所以提醒一下,大家见笑!