sqldelphifirebirddbexpress

How do I access the result of a Select count(*) using an SQLQuery component in Delphi


I am using Delphi RAD Studio 9 and Firebird 2.5

I want to use the count of the number of rows that fit a certain condition. When I put

Select count(*) from VRDB where Lname - 'SMITH'

into the the SQL property , upon opening SQLQuert1, I get the error message

SQLQuery1: Unable to determine field names for %s.

I assume this means Firebird or Delphi doesn't know what to do with the result.

How do I trap the result of the query? (My query statements work fine using isql.)


Solution

  • Using a Firebird database in Delphi 10 Seattle, the following works fine for me:

    procedure TForm2.btnCountClick(Sender: TObject);
    begin
      SqlQuery3.Sql.Text := 'select count(*) from maimages';
      SqlQuery3.Open;
      Caption := IntToStr(SqlQuery3.Fields[0].AsInteger);
    end;
    

    Btw, which Delphi version do you mean by "RAD Studio 9"? In case you mean Delphi 2009, the earliest Delphi version I have after D7 is XE4, and the above code also works fine with that.