with query1 do
 begin
  close;
  with sql do
   begin
    clear;
    add('select QuestionDesc as questiondecs1 from tian');    add('where ID='+inttostr(number));
    
   end;
  open;
 end;
 tianrecord.questiondesc:=query1.fieldbyname('questiondecs1').AsString;
其中QuestionDesc字段为access数据库表中的字段类型为文本,字段大小为255
记录tianrecord的questiondesc为string类型

解决方案 »

  1.   

    add('where ID='+inttostr(number));这一句
    改成这样add('where ID='''+inttostr(number)+'''');try it
      

  2.   

    add('select QuestionDesc as questiondecs1 from tian');    add('//这里要有空格 where ID='+inttostr(number));
      

  3.   

    没有加SQL本身的引号!
    这样:
    add('where ID='''+inttostr(number)+'''');
      

  4.   

    出的是什么错?
    是否where的前面没有空格.
      

  5.   

    ID是字符型么?是的话要加引号:QuotedStr(inttostr(number))
      

  6.   

    不用空格吧.....两次ADD已经换行了
      

  7.   

    add('where ID='''+inttostr(number)+'''');
      

  8.   

    先把你出的错告诉我们,
    试试在where前加空格
      

  9.   

    SQL语句的字符串应该有引号!
    add('//这里要有空格 
        where ID='+''''inttostr(number)+'''');
      

  10.   

    对不起,上句有错误,更正为
    add('//这里要有空格 
        where ID='+''''+inttostr(number)+'''');
      

  11.   

    就是执行后,我想察看
    query1.fieldbyname('questiondecs1').AsString
    他说query1.fieldbyname('questiondecs1').asstring: Variable 'Self' inaccessible here due to optimization
    为啥?
      

  12.   

    with query1 do
     begin
      close;
      with sql do
       begin
        clear;
        add('select QuestionDesc as questiondecs1 from tian' + #13);    add('where ID= :aNumber');
       end;
      ParamByName('aNumber').Value := Number;//这样无论你是什么值都可以通用了
      open;
     end;
      

  13.   

    大哥
    执行后:
    tianrecord.questiondesc还是空
    我察看
    query1.fieldbyname('questiondecs1').AsString
    他说query1.fieldbyname('questiondecs1').asstring: Variable 'Self' inaccessible here due to optimization
    为啥?
      

  14.   

    大哥:
       会不会是我把这段代码放在form.show里的原因呀?
      

  15.   

    add('//这里要有空格 
        where ID='+inttostr(number)+'''');
      

  16.   

    Project|Options|Compiler
    關掉optimizations先項
      

  17.   

    showmessage(query1.fieldbyname('questiondecs1').AsString);
    还有,你这条SQL语句在access库中运行能查到数据吗
      

  18.   

    ID为整型就应该是"strtoint"
    add('where ID='+strtoint(number));
        
      

  19.   

    大哥:
    附值语句
    tianrecord.questiondesc:=query1.fieldbyname('questiondesc1').AsString;
    附值符不过去?
    其中
    tianrecord:Trecord
    type Trecord=record
                 questiondesc:string;
                 answer:string;
                 useranswer:string;
                 correct:boolean;
                 score:integer;
                 end;
      

  20.   


    tianrecord.questiondesc:=query1.fieldbyname('questiondecs1').AsString;
    其中QuestionDesc字段为access数据库表中的字段类型为文本,字段大小为255
    记录tianrecord的questiondesc为string类型query1.open;//打開QUERY1
    if not query1.Eof then//請保證此時Query1的數據集有數據
      tianrecord.questiondesc:=query1.fieldbyname('questiondecs1').AsString;
      

  21.   

    应该用Stream附值,具体查一下帮助
      

  22.   

    query1.fieldbyname('questiondecs1').AsString是有值的
    但就是
    tianrecord.questiondesc:=query1.fieldbyname('questiondecs1').AsString;
    后tianrecord.questiondesc没有值
      

  23.   

    with query1 do
     begin
      close;
      with sql do
       begin
        clear;
        add('select QuestionDesc as questiondecs1 from tian ');    add(' where ID='+inttostr(number));
        
       end;
      open;
     end;