var str:string;
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select A from table1 where B:=text');
adoquery1.open;
str:=adoquery1.fieldbyname('A').asstring;
上面的语句是不是能得到一条记录中字段B=text 的字段A的值?
如不能,该如何得到条件下字段A的值

解决方案 »

  1.   

    adoquery1.sql.add('select A from table1 where B=''text''');
      

  2.   

    var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B='+#39+'text'+#39);
    adoquery1.open;
    str:=adoquery1.fieldbyname('A').asstring;
      

  3.   

    你写错了,应为:
    var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B='''+text+'''');
    str:=adoquery1.fieldbyname('A').asstring;
    adoquery1.open;
      

  4.   

    to haoco(程序员) 
    你的Code是错误的!
    var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B:='''+text+'''');//text为变量
    adoquery1.open;
    str:=adoquery1.fieldbyname('A').asstring;
    //------------------------------------------------
    var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B:=''text'');//text为字符串
    adoquery1.open;
    str:=adoquery1.fieldbyname('A').asstring;
      

  5.   

    上面错了!:) var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B='''+text+'''');//text为变量
    adoquery1.open;
    str:=adoquery1.fieldbyname('A').asstring;
    //------------------------------------------------
    var str:string;
    begin
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select A from table1 where B=''text'');//text为字符串
    adoquery1.open;
    str:=adoquery1.fieldbyname('A').asstring;
      

  6.   

    也可以这样:adoquery1.sql.add('select A from table1 where B=' + QuotedStr('text'));//if text是字串adoquery1.sql.add('select A from table1 where B=' + QuotedStr(text));//if text是字串变量
      

  7.   

    adoquery1.sql.add('select A from table1 where B:='''+text+'''');//text为变量
      

  8.   

    adoquery1.sql.add('select A from table1 where B=''text''');
      

  9.   

    adoquery1.sql.add('select A from table1 where B='''+text+'''');//text为变量(不能有B:)