Select data from MySql database based on the date selected in the DateTimePicker

  • Thread starter Thread starter nigelsvision
  • Start date Start date
N

nigelsvision

Guest
Hi, I have a windows form using VB.NET I have a table called Users a column called TimeDate and the Data type in the MySQL database is DateTime

I am inserting the date and time into a MySQL database with a DateTimePicker and a button. When the date and time are in the database it looks like 28/02/2020 17:52:49

I want to use another DateTimePicker to retrieve that data from the database based on the date selected ignoring the time which is irrelevant for the retrieval. I want the data to be displayed in a DataGridView.


To retrieve the data I have a button

Dim Query As String
mySQLcon = New MySqlConnection With {
.ConnectionString = "server=address; userid=name; password=password; database=dbname"
}
Try
mySQLcon.Open()
Query = "select * FROM Users WHERE TimeDate >= @StartDate "
Command = New MySqlCommand(Query, mySQLcon)
Dim lrd As MySqlDataReader = Command.ExecuteReader()
If lrd.HasRows Then
lrd.Read()
Command.Parameters.AddWithValue("@StartDate", DateTimePicker2.Value)
da = New MySqlDataAdapter(sql, con)
da.Fill(dt)
DataGridView1.DataSource = dt

mySQLcon.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Im getting an error saying Fatal error during command execution. vCan someone put me right.


Thanks

Continue reading...
 


Write your reply...
Back
Top