TSqlQuery执行count(*)

刚开始用Delphi,正在看dbExpress部分,想用TSqlQuery查询表内总共多少条记录,找了好多资料这里总结下:


方法1.

sqQuery.SQL.Clear;
sqQuery.SQL.Add('select count(*) from Books;');
sqQuery.Open();
ShowMessage(sqQuery.Fields[0].AsString);
sqQuery.Close;

方法2.

sqQuery.SQL.Clear;
sqQuery.SQL.Add('select count(*) from Books;');
sqQuery.ExecSQL;
ShowMessage(IntToStr(sqQuery.RecordCount));



你可能感兴趣的:(Delphi)