Home TADOQuery returns empty recordset in second execution
Reply: 1

TADOQuery returns empty recordset in second execution

Stefano Losi
1#
Stefano Losi Published in 2018-02-09 16:49:34Z

I have quite an incredible situation using a TADOQuery against an MS Access database.
In the following code (just a test case), the first execution of the query returns the correct record, the second execution instead returns an "empty" record (i.e. the codFormula variable first time is 'E0275', second time is '').

Obviously the three parameters value are the same

  QryDosaggioTestata.Parameters[0].Value := idBatchRottura;
  QryDosaggioTestata.Parameters[1].Value := nrMiscelataRottura;
  QryDosaggioTestata.Parameters[2].Value := dataBatchRottura;

  QryDosaggioTestata.Open;
  //  Here, QryDosaggioTestata's RecordCount is 1 and Eof is False
  codFormula := trim(QryDosaggioTestataCodiceFormula.Value);
  //now codFormula = 'E0275'
  QryDosaggioTestata.Close;

  QryDosaggioTestata.Parameters[0].Value := idBatchRottura;
  QryDosaggioTestata.Parameters[1].Value := nrMiscelataRottura;
  QryDosaggioTestata.Parameters[2].Value := dataBatchRottura;

  QryDosaggioTestata.Open;
  //  Here, QryDosaggioTestata's RecordCount is 0 and Eof is True
  codFormula := trim(QryDosaggioTestataCodiceFormula.Value);
  // now codFormula = ''
  Ora := QryDosaggioTestataOra.Value;
  QryDosaggioTestata.Close;

The query text is in the designer object:

Select * from LOG_FINE_DOSAGGIO
WHERE
idBatch = :parIdBatch
AND nrMiscelata = :parNrMiscelata
AND Data = :parData

Obviously the query is syntactically correct, otherwise it would not execute well the first time. Thanks a lot.

Stefano Losi
2#
Stefano Losi Reply to 2018-02-10 21:32:37Z

After many attempts I got the clue: the Microsoft JET OLEDB 4.0 provider deals horribly with date parameters: the only way to make it work is, for date parameters, to set the parameter datatype to ftString and to pass the value as DateToStr(yourDate).

My impression is that after first query.Close, the query parameters are re-prepared in the wrong way by the provider.

Hope this helps anyone. Everything works well with other parameters type (i.e. integer, string...) and with SQL Server provider.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313973 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO