查询统计一个表里某个字段的数目,并且把统计结果赋给变量tempstr1!,程序是这样的:
if adoquery3.Active then adoquery3.Close;
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名 adoquery3.ExecSQL;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from patient');
adoquery3.Open;
tempstr1:=adoquery3.FieldValues['pp'];
但是总出错!
请各位指点,谢谢
if adoquery3.Active then adoquery3.Close;
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名 adoquery3.ExecSQL;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from patient');
adoquery3.Open;
tempstr1:=adoquery3.FieldValues['pp'];
但是总出错!
请各位指点,谢谢
adoquery3.SQL.clear;
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名 adoquery3.Open;
tempstr1:=adoquery3.FieldValues['pp']; //这里给tempstr1赋值//以下代码是干嘛的?
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from patient');
adoquery3.Open;
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名
//需要返回数据集的应使用Open或Active := true;
// adoquery3.ExecSQL;
adoquery3.Open;
//在adoquery3数据集中返回pp
tempstr1:=adoquery3.FieldValues['pp'];
//Close事件后清除数据集,当然得不到PP
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from patient');
adoquery3.Open;
// tempstr1:=adoquery3.FieldValues['pp'];
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名 adoquery3.open;//open是返回集的sql操作方法,exec是不返回数据集的,比如delete 和 update等sql操作
tempstr1:=adoquery3.Fields[0].asstring;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.text:='select * from patient';//如果这里再是sql.add的话,那么会加上上面的
select count(patientpro) as pp from tblpatient这句sql语句的!!最好使用.SQL.text这种sql语句赋值方法!!
adoquery3.Open;
adoquery3.recordset:=adoconnetion.execute(''select count(patientpro) as pp from tblpatient'')
tempstr1:=adoquery3.fieldbyname('pp').asstring;
adoquery3.SQL.Add('select count(patientpro) as pp from tblpatient');//pp是统计结果别名 adoquery3.Open;
tempstr1:=adoquery3.FieldValues['pp'];
var
tempstr1:String;
with AdoQuery3 do
begin
close;
sql.clear;
sql.add('select count(patientpro) as pp from tblpatient');
Open;//要返回值用Open,不要返回值用 ExecSQL
tempstr1:=FieldByName('pp').AsString;
close;
end;