Click on DatabaseException and it may give you more information. I don’t think the problem is the date format, the error is before executing the command on the database.
I haven’t downloaded your program, I don’t have Microsoft Access but I will take a look later today to see if I can help more.
Edit: sorry I can’t help more, I can’t load the database to see the DatabaseException that you are getting:
If you can change your sample code to use SQLite and you get the same error then I can help.
I was able to find an online tool to change the Access database to SQLite. After fixing a couple of problems for non-English systems, I don’t get an error there.
Also added the db ID to the calendar:
ID 24, 8 and 16 are part of May (the code test each day of the month to see if there is a record on the db).
Ok, but the database that I have in Access … that of the Calendar is only a part, there are many other tables … It is something related to the date, because I have simplified the code, written for a search from the Object field and everything works … but with the date field I still can’t.
Var RecordFinder As RowSet
'RecordFinder = db.SelectSQL("SELECT * FROM Promemoria where Data=DATEVALUE("+dataesaminata.shortdate + ")")
RecordFinder = db.SelectSQL("SELECT * FROM Promemoria where Oggetto='Prova2'")
Dim i as integer=0
While Not RecordFinder.AfterLastRow
i=i+1
'Conta i campi del record
'For i As Integer = 0 To RecordFinder.LastColumnIndex
'dataList.CellTextAt(dataList.LastAddedRowIndex, i) = rs.ColumnAt(i).StringValue
'messagebox i.ToString
'Next
RecordFinder.MoveToNextRow
Wend
messagebox " Ci sono " + i.ToString + " records che soddisfano la ricerca"
RecordFinder.Close
I’m sorry I can’t help you fix your problem with Access database, don’t have experience nor installed here.
A couple of things you can do:
in Promemoria Opening event you have d.ShortDate, this will later create year as 22 and not 2022, so your SQLDate later is 0022-05-18 for today and not 2022-05-18
as you said, the date field on your database has SQLDateTime, if the Time is always 00:00:00 then you may try to use dataesaminata.SQLDateTime
if that doesn’t work, maybe you can try DATA LIKE instead of DATA =
Okay, in the meantime, thanks for your help. I got around the problem with the following code. But there is no way that there is no way to create a condition for the query.
Var RecordFinder As RowSet
dim DataFormattata as new date
RecordFinder = db.SelectSQL("SELECT * FROM Promemoria")
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
Unless you can trust the date values 100%, this is a dangerous thing to do as you are opening yourself up to an SQL injection attack. See SQL injection - Wikipedia