Link to home
Start Free TrialLog in
Avatar of isrxl
isrxl

asked on

VB.net, Access & date/time picker: writing sql query to find units available for reservation between 2 given dates

Greetings:

As mentioned, I'm working with VB.NET Windows Form and an Access DataBase. A table in the database stores room numbers and the reservation dates for these rooms (resArrivalDate & resDepartureDate) among other things.

I have, in the Form, 2 date/time picker controlls used to pick a start and an end dates to search for availability of the rooms between the two dates selected. The results should be displayed on a datagrid controll but for some reason my query doesn't seem to work; it returns all of the rooms regardless of their availability.

Here's the code used in the search function:

        Dim vacancySearchSQL As String = "SELECT * FROM ProMARS.tblReservations WHERE resDepartureDate < " &    dtpSrchStartDate.Text & " OR resArrivalDate > " & dtpSrchEndDate.Text
        Dim vacancySearchDataAdapter As New OleDbDataAdapter(vacancySearchSQL, gblConnection)
        Dim vacancySearchDataSet As New DataSet
        Try
            vacancySearchDataAdapter.Fill(vacancySearchDataSet, "tblReservations")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Try
            dgVacancyResults.SetDataBinding(vacancySearchDataSet, "tblReservations")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Sorry if the question seems silly, but I haven't had much experience dealing with databases and time. Your help or pointing me to a source with good information on this would be greatly appreciated. Thank you.
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of isrxl
isrxl

ASKER

Dear amit g, thank you so much, you saved the day for me.
Glad to be of help :)