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 (checkin and checkout) among other things.

Here's the code used in the search function:
 provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
        'Change the following to your access database location
        dataFile = "C:\Users\fongf\Desktop\FYP_Database\FYP.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString

        'the query:
        Dim cmd As String = "SELECT * FROM Reservation WHERE (checkin > " & "#" & DateTimePicker1.Text & "#" & " and checkin > " & "#" & DateTimePicker2.Text & "#" & ")" & " or " & "(checkOut < " & "#" & DateTimePicker2.Text & "#" & " and checkOut < " & "#" & DateTimePicker1.Text & "#" & ")"
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        If reservation = True Then
            MsgBox("Sorry, this room was booked", MsgBoxStyle.OkOnly, "Invalid Login")
            MsgBox("all is ok")
        End If

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.
gary chiamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
I see 2 things.

The first one is that your query (a string) is named cmd (probably for Command) but a string does not have a ExecuteReader method. A command has. Have a look at https://msdn.microsoft.com/en-us/library/979byfca(v=vs.110).aspx

The second thing is about the query. With all the concatenation you are doing, it is somewhat hard to read. Also the BETWEEN operator would make it clearer (at least for me):

        Dim sql As String = "SELECT * FROM Reservation WHERE (checkin BETWEEN #" + DateTimePicker1.Value.Tostring("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.Tostring("yyyy/MM/dd") & "# ) or (checkOut BETWEEN #" & DateTimePicker2.Value.Tostring("yyyy/MM/dd") & "# and #" & DateTimePicker1.Value.Tostring("yyyy/MM/dd") & "#)"

Open in new window

gary chiamAuthor Commented:
Mr.Eric , can you show me some example about how to do the availability of hotel room with room number , checkIn (datetimepicker1)  and checkOut(datetimepicker2) ?
Your help i really  appreciated.
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

Éric MoreauSenior .Net ConsultantCommented:
without having a database table structure, I would say that the query here above is good.

Your second link is showing you to use an OleDbCommand exactly like I told you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongSoftware Team LeadCommented:
How's your window form's interface looks like?

can you provide the table structures with sample data?
Éric MoreauSenior .Net ConsultantCommented:
I received a Thumbs up on that comment from the asker
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.