i need to filter my table between 2 dates

but it makes wrong filtering really i dont understand why. but it might be my wrong codes

here is my codes... what should i do?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim da As New SqlDataAdapter("SELECT * FROM TableName WHERE DateColumn BETWEEN '" & _
   DateTimePicker1.Value & "' AND '" & DateTimePicker2.Value & "'", Connection) 
   Dim dt As New DataTable
   da.Fill(dt)
   Dim dv As New DataView(dt)
   DataGridView1.DataSource = dv
End Sub

Thanks for your helping :)

Recommended Answers

What do you mean by wrong filtering? It's returning something it shouldn't or not returning something that it should?

Anyway, I would try DateTimePicker.Value.ToString("yyyy-MM-dd")

Jump to Post

All 2 Replies

What do you mean by wrong filtering? It's returning something it shouldn't or not returning something that it should?

Anyway, I would try DateTimePicker.Value.ToString("yyyy-MM-dd")

It's returning something it shouldn't.

Also its works ===> DateTimePicker.Value.ToString("yyyy-MM-dd")

ahh right now i understand....

Thank you very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.