Parameterized ADOQuery
-
I have inherited a Delphi project, and as a non-Delphi programmer I am only just getting to grips with its various strange idiosyncrasies. One aspect of the application I am working on relates to an ADOQuery, and the formats with dates. The query is written parameterized, however I have noticed incorrect datasets particularly at the start of a new month. I am guessing this is due to the SQL syntax normally using the US date format, whereas the system date is in the UK format. I googled a few attempts at setting the date format, and found that using the parameterized is the best version, as then it doesn't matter what format is passed. However I can't get the suggested methods to compile, using the AsDateTime:
adoQuery.Parameters.ParamByName('TimeNow').AsDateString
Example from http://en.allexperts.com/q/Delphi-1595/2009/2/School-Project-2.htm[^] Any hints on how to handle this situation?
-
I have inherited a Delphi project, and as a non-Delphi programmer I am only just getting to grips with its various strange idiosyncrasies. One aspect of the application I am working on relates to an ADOQuery, and the formats with dates. The query is written parameterized, however I have noticed incorrect datasets particularly at the start of a new month. I am guessing this is due to the SQL syntax normally using the US date format, whereas the system date is in the UK format. I googled a few attempts at setting the date format, and found that using the parameterized is the best version, as then it doesn't matter what format is passed. However I can't get the suggested methods to compile, using the AsDateTime:
adoQuery.Parameters.ParamByName('TimeNow').AsDateString
Example from http://en.allexperts.com/q/Delphi-1595/2009/2/School-Project-2.htm[^] Any hints on how to handle this situation?
-
Hello, I would do like this;
adoQuery.Parameters.ParamByName('TimeNow').DataType := ftDateTime;
adoQuery.Parameters.ParamByName('TimeNow').Value := mydatevalue; -
Hello, I would do like this;
adoQuery.Parameters.ParamByName('TimeNow').DataType := ftDateTime;
adoQuery.Parameters.ParamByName('TimeNow').Value := mydatevalue;Thanks to both for the replies. After some experimentation, I found that it was necessary to set the DataType for the parameter, else it did not give correct datasets for the query.