lundi 26 juin 2017

VB Reservation Program Check if Date Falls between Range

I am wondering if some one might be able to assist me with my VB code. I believe I am close, because a lot of the time my code works just fine but I noticed that there might be a weakness to it because at times I get unexpected results. I am thinking I am missing something pretty basic here so bear with me!

Basically, I am trying to create a simple hotel reservation system in a Data Table for a VB project that I created just playing around in my spare time.

What I hope to be able to accomplish is for a user to be able to select a room number from a list box then pick an arrival and departure date. After this happens and they click a button I want the program to be able to compare the Room Number along with the beginning date of the reservation and the end date of the reservation with the room number, beginning Dates and end dates in each row already inside of the Data Table. Anyway, here is basically how my If Statement is structured so far:

For Each data As DataRow In dtRoomReserveData.Rows
                    If data.Item("RoomNum").ToString.Contains(lstSelectRoomNum.Text) AndAlso data.Item("DateArrive") >= dateArrive.Value.Date AndAlso dr2.Item("DateArrive") <= dateLeave.Value.Date Then

                        'if there is a reservation in room exists during that Date range display error message to user:
                        MessageBox.Show("Sorry!  That room is already reserved on during that date!")
                        Exit Sub


                    End If

                Next

Any help offered is greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire