I cannot load Firebird data into Delphi XE2 using Tzquery

Asked

Viewed 134 times

0

I have a Tzquery created, and I try to load the fields SEQ_CTE and SERIE_CTE according to the code below:

ZQuery1.sql.text :=
    'select * from C000004 where filial = '' + frmprincipal.spanel1.caption + ''';
  ZQuery1.open;
  ZQuery1.execsql;

  DBEdit2.text := ZQuery1.fieldbyname('SEQ_CTE').asstring;
  eserie.text := ZQuery1.fieldbyname('SERIE_CTE').asstring;

  showmessage(ZQuery1.fieldbyname('SERIE_CTE').asstring);

  ZQuery1.close;

The answer that the system returns is an empty datum, but in the database there are data. Does anyone know how I can fix this?

Additional information: the SQL code is correct because I tried to generate it by Delphi and then run in Firebird and returned the data correctly.

  • 2

    the biggest problem of the above code is that the command open is what you want, it executes the SQL command and returns the data to the Dataset. o execSql is for SQL data changes, which do not return tuples for Dataset. Even in the answer Execsql is unnecessary, and using parameters was a good solution

1 answer

2


I managed to solve in a very interesting way, that I saw in this video: https://www.youtube.com/watch?v=Tp8D9tYRX34

To solve, I went to the property to stop the components and created a call Tfilial

In the SQL property I put the following code: select * from C000004 where filial = :Tfilial

My code cited above was like this:

ZQuery1.Params.ParamValues['Tfilial'] := frmprincipal.spanel1.caption;
  ZQuery1.execsql;
  ZQuery1.Active := true;

  DBEdit2.text := ZQuery1.fieldbyname('SEQ_CTE').asstring;
  eserie.text := ZQuery1.fieldbyname('SERIE_CTE').asstring;

  showmessage(ZQuery1.fieldbyname('SERIE_CTE').asstring);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.