procedure TForm1.Button43Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as a from stgk1 where 成立时间 between :a and :b ');
ADOQuery1.Parameters.ParamByName('a').Value:=datetimepicker13.datetime ;
ADOQuery1.Parameters.ParamByName('b').Value:=datetimepicker14.datetime;
prepared:=true;
execsql;
showmessage('1');
edit88.Text=inttostr(adoquery1.Fields[0].Value);
showmessage('2');
end;
end;运行的时候 showmessage('1');的窗体可以出来,但是showmessage('2');的窗体没有出来,
报错是list index out of bounds(0)
也就是运行edit88.Text=inttostr(adoquery1.Fields[0].Value);出现错误。
还有一种是将execsql换成open,一运行程序,报错EoleException with message‘未指定的错误’求各位帮忙解答一下,小弟是Delphi菜鸟
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select count(*) as a from stgk1 where 成立时间 between :a and :b ');
ADOQuery1.Parameters.ParamByName('a').Value:=datetimepicker13.datetime ;
ADOQuery1.Parameters.ParamByName('b').Value:=datetimepicker14.datetime;
prepared:=true;
execsql;
showmessage('1');
edit88.Text=inttostr(adoquery1.Fields[0].Value);
showmessage('2');
end;
end;运行的时候 showmessage('1');的窗体可以出来,但是showmessage('2');的窗体没有出来,
报错是list index out of bounds(0)
也就是运行edit88.Text=inttostr(adoquery1.Fields[0].Value);出现错误。
还有一种是将execsql换成open,一运行程序,报错EoleException with message‘未指定的错误’求各位帮忙解答一下,小弟是Delphi菜鸟
而且不是prepared:=true吧。直接用prepare方法
close;
sql.Clear;
sql.Add('select count(*) as a from stgk1 where 成立时间 between :a and :b ');
prepare;
ADOQuery1.Parameters.ParamByName('a').Value:=datetimepicker13.datetime ;
ADOQuery1.Parameters.ParamByName('b').Value:=datetimepicker14.datetime;
open;
查询一般用open。其他的insert,update,delete才用execsql.
begin
close;
sql.clear;
sql.add(...);
prepare;
parameters.ParamByName('a').Value:=datetimepicker13.datetime;
parameters.ParamByName('b').Value:=datetimepicker14.datetime;
open;
end;
问题是如果只写prepare,会报错 Undeclared identifier: 'prepare'
execsql;
这两句去掉
然后加一句Open;