Hi group, I have a big problem.
I have an access database with short dates. I perform a comparison in the SQL … where Data = DataFormattata.short and it doesn’t go … if instead in the query I delete the where and execute an If Data = DataFormattata.short … it works.
Var RecordFinder As RowSet
dim DataFormattata as new date
RecordFinder = db.SelectSQL("SELECT * FROM Promemoria where Data="+ dataesaminata.shortdate)
Dim i as integer=0
While Not RecordFinder.AfterLastRow
DataFormattata=RecordFinder.Column("Data").DateValue
'if dataesaminata.shortDate=DataFormattata.ShortDate then
messagebox "Trovata corrispondenza fra le date " + DataFormattata.ShortDate
i=i+1
'end if
RecordFinder.MoveToNextRow
Wend
messagebox " Ci sono " + i.ToString + " records che soddisfano la ricerca"
RecordFinder.Close
That said the message in the image in side the red square tells you what’s wrong
The DATA column in the database is a DATE
The value your trying to use for the query is a STRING
That wont work
So we need to make sure they match
try
RecordFinder = db.SelectSQL("SELECT * FROM Promemoria where Data=DATEVALUE('"+ dataesaminata.shortdate + "')" )
the SQL function DATEVALUE takes a string and turns it into a DATE data type
I don’t have time to test this against an ODBC database, but I wonder if the built-in “prepared statement” functionality of SelectSQL will do the transformation automatically? So like this:
RecordFinder = db.SelectSQL("SELECT * FROM Promemoria where Data=?", dataesaminata)