Previous information: I have a database with a Date / Time type field in Access (dd / mm / yy to hh: mm: ss). The idea is to put a date (entered in three TextBox TBDia
TBMes
TBAnio
) and that I take the records of that date (to see the hours) in a DataGridView
called DGVFechas
. This is my code:
'cogemos la fecha de los TextBox'
Dim fecha As Date = DateSerial(TBAnio.Text, TBMes.Text, TBDia.Text)
'cogemos todos los datos de la fecha'
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=F:\CrossChex.mdb")
con.Open()
Dim query2 As String = "SELECT CheckTime, CheckType FROM Checkinout WHERE CheckTime = " & fecha
Dim DA2 As New OleDbDataAdapter(query2, con)
Dim DT2 As New DataTable
DA2.Fill(DT2)
DGVFechas.DataSource = DT2
'cambiamos el nombre de las columnas del DataGridView'
DGVFechas.Columns(0).HeaderText = "Horas"
I've tried declaring fecha
as string
and I have not been able to make it work either. I guess the fault is in the query, which will not be "=" but "LIKE" or similar, but I have already tried all the combinations that have occurred to me and I have not found the form.
There are fragments of code that I have deleted since they are not important for this failure, maybe I have removed something more but I think that is not the case.
Thank you very much in advance!