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类型
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类型
改成这样add('where ID='''+inttostr(number)+'''');try it
这样:
add('where ID='''+inttostr(number)+'''');
是否where的前面没有空格.
试试在where前加空格
add('//这里要有空格
where ID='+''''inttostr(number)+'''');
add('//这里要有空格
where ID='+''''+inttostr(number)+'''');
query1.fieldbyname('questiondecs1').AsString
他说query1.fieldbyname('questiondecs1').asstring: Variable 'Self' inaccessible here due to optimization
为啥?
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;
执行后:
tianrecord.questiondesc还是空
我察看
query1.fieldbyname('questiondecs1').AsString
他说query1.fieldbyname('questiondecs1').asstring: Variable 'Self' inaccessible here due to optimization
为啥?
会不会是我把这段代码放在form.show里的原因呀?
where ID='+inttostr(number)+'''');
關掉optimizations先項
还有,你这条SQL语句在access库中运行能查到数据吗
add('where ID='+strtoint(number));
附值语句
tianrecord.questiondesc:=query1.fieldbyname('questiondesc1').AsString;
附值符不过去?
其中
tianrecord:Trecord
type Trecord=record
questiondesc:string;
answer:string;
useranswer:string;
correct:boolean;
score:integer;
end;
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;
但就是
tianrecord.questiondesc:=query1.fieldbyname('questiondecs1').AsString;
后tianrecord.questiondesc没有值
begin
close;
with sql do
begin
clear;
add('select QuestionDesc as questiondecs1 from tian '); add(' where ID='+inttostr(number));
end;
open;
end;