现有程序
a:integer;
.....
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select count(*) from test where num=1');
query1.Prepare;
query1.ExecSQL;如何将此统计结果赋给一个整型变量?
a:integer;
.....
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select count(*) from test where num=1');
query1.Prepare;
query1.ExecSQL;如何将此统计结果赋给一个整型变量?
query1.SQL.Clear;
query1.SQL.Add('select count(*) as mm from test where num=1');
query1.Prepare;
query1.open;
a:=strtoint(query1.fieldbyname('mm').value);
[Error] unit1.pas(73): ')' expected but identifier 'value' found
query1.SQL.Clear;
query1.SQL.Add('select count(*) as mm from test where num=1');
query1.open;
try a:=strtoint(query1.fieldbyname('mm'));
except showmessage('出错');
end;
query1.Close;
except showmessage('出错');
处理成 a:=0
也就是说:
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select count(*) as mm from test where num=1');
query1.open;
try a:=strtoint(query1.fieldbyname('mm'));
except a:=0;
end;
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select count(*) as mm from test where num=1');
query1.open;
if not query1.isempty then a:=strtoint(query1.fieldbyname('mm'));
else a:= 0;
query1.Close
可以不用异常的话,还是不要触发异常的好!
a:=query1.fieldbyname('mm').asinteger;
var
num: Integer;
begin
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * from test where num=1');
query1.open;
num := query1.RecordCount; //就是这个了
query1.Close
end;