1

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.

4

1 回答 1

1

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.

于 2018-02-10T21:32:37.870 回答