Currently I have a button, 2 datetimepickers, a datagridview, and a combobox. What I like to do is the user will select the FromDate and ToDate and then with a keyword from a combobox it will search in a datagridivew according to the date range and the combobox's value.

I already implemented a search function for the combobox in the button click event:

 Dim con As New OleDbConnection(Get_Constring)
 Dim dt As New DataTable
 con.Open()
 Dim da As New OleDbDataAdapter("SELECT * from EncodingComplete where Client like '" & ComboBox1.Text & "%'", con)
 da.Fill(dt)
 DataGridView1.DataSource = dt
 con.Close()

How would I code the date range?

Recommended Answers

All 2 Replies

Hi

Do you want to include the DateRange within your SQL statement? If so, you could use the BETWEEN operator, for example:

SELECT * FROM EncodingComplete WHERE YourDateField BETWEEN #01/01/2010# AND #01/01/2011#

Note, depending on the database you are using you may need to substitue the # character with a ' character. I believe Access uses # and SQL Server uses ' but may be wrong.

HTH

I don't include that in my SQL statement. Let me try then I will inform you.

Be a part of the DaniWeb community

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