Click here to Skip to main content
15,910,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day Please can some one help me out here
I am trying to search my database to get the result out Kindly see below

C#
DataTable dt = try.Query(" select Rooms.RoomId, Rooms.RoomType From Rooms INNER JOIN Reservations ON ( Rooms.RoomId = Reservations.RoomId ) AND GETDATE() BETWEEN Reservations.CheckInDate AND Reservations.CheckOutDate ORDER BY Rooms.RoomType");
       if (dt.Rows.Count > 0)
       {
           LblMessage.Text = " No Room Available";
       }
       else
       {
           DataTable dt1 = try.Query( "Select  Rooms.RoomType, Rooms.PricePerNight From Rooms INNER JOIN Reservations ON (Rooms.RoomId != Reservations.Roomid) ORDER BY Rooms.Roomtype");

           if (dt1.Rows.Count > 0)
           {
               GridResult.DataSource = dt1;
               GridResult.DataBind();
           }
           else
           {
               LblMessage.Text = "No Rooms Availble";
           }


When i search i don't get any available rooms "No Rooms Availble" is what will come up, I have so many rooms available
how do i correct it

thanks in advance
Posted

1 solution

Try this query. Not sure as I dont have the data to verify. Give it a try.

SQL
select Rooms.RoomId, Rooms.RoomType From Rooms INNER JOIN Reservations ON ( Rooms.RoomId = Reservations.RoomId ) AND GETDATE() NOT BETWEEN Reservations.CheckInDate AND Reservations.CheckOutDate ORDER BY Rooms.RoomType
 
Share this answer
 
Comments
Difameg Network Nigeria 12-Jul-13 7:49am    
Thanks, but the querry you gave is to search the reservation to check if there is reservation i guess

i don't have any data in the reservations table, but do have data on rooms table,
How do i search the rooms table and compare it with the reservations table to befor populating the result like


DataTable dt1 = try.Query( "Select Rooms.RoomType, Rooms.PricePerNight From Rooms INNER JOIN Reservations ON (Rooms.RoomId != Reservations.Roomid) ORDER BY Rooms.Roomtype");

if (dt1.Rows.Count > 0)
{
GridResult.DataSource = dt1;
GridResult.DataBind();
}
else
{
LblMessage.Text = "No Rooms Availble";
}
Please help me correct it is wrong
ArunRajendra 12-Jul-13 9:27am    
Yes, if the current date is between the checkin and checkout date then there is reservation. It should be NOT between to check for no reservation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900