1 Previous Next 

Date time Date Property


Often is asked in the forum how to use a date from a datetimepicker or calendar for a database. Sometimes persons start in a difficult way to use the text. However, the Date part from the Value property must be used.
Public Class Form1
    Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgsHandles DateTimePicker1.ValueChanged
        Dim dt As New DataTable
        Using da As New OleDb.OleDbDataAdapter("SELECT * FROM Orders WHERE OrderDate = ?""Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\nwind.mdb")
            da.SelectCommand.Parameters.AddWithValue("?", DateTimePicker1.Value.Date)
            da.Fill(dt)
            DataGridView1.DataSource = dt
        End Using
    End Sub
End Class



1 Previous Next