Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my database

emp_no date time seatno
1 04/05/2012 9:00 am s-5
2 05/05/2012 10:00 am s-2
3 04/05/2012 9:00 am s-1


i have 2 buses running at 9 am and 10 am

i need to check if

my 04/05/2012 9:00 am bus seat no s-5 is reserved then


imagebtn.url="..jpg"

same way if 05/05/2012 10:00am bus no seat is reserved then

imagebtn.url="....jpg"

so for all the dates and both buses and all the seats


i need the code for page load

if reserved then image change (checking from sql) ????
Posted
Updated 2-May-12 17:40pm
v5
Comments
AmitGajjar 3-May-12 0:40am    
what type of display control you are using for displaying your result ? if you are using grid to show available bus then you can use ItemTemplate there.
mani.kishore.asp.net 3-May-12 0:52am    
NO IMAGE BUTTON

Dim sqlselect As String
sqlselect = " SELECT trpbus_seatno FROM trpbus_bookdata where trpbus_date='" & textbox_date.Text & "' and trpbus_time = '" & Label_deptime.Text & "'"


Dim myConnection As New SqlConnection(Utility.CurrentConnectionString)
Dim myCommand As New SqlCommand(sqlselect, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
If myReader.HasRows Then
While myReader.Read()
Dim seat As String = (myReader("seat")).ToString()
If seat = "S-1" Then
ImageButton_seat_1.ImageUrl = seatno_booked
ElseIf seat = "S-2" Then
ImageButton_seat_2.ImageUrl = seatno_booked
ElseIf seat = "S-3" Then
ImageButton_seat_3.ImageUrl = seatno_booked
ElseIf seat = "S-4" Then
ImageButton_seat_4.ImageUrl = seatno_booked
End If

End While
End If
myReader.Close()

1 solution

Above code would not help you. You have multiple records and you play with one imagebutton all the while.

Instead of using DataReader, use DataAdapter to fetch the data. Once you have data in a datatable/dataset, then loop through each row of it and set the imagebutton url for that row accordingly.

BTW, above SQL query, how do you know which seat numbers are not booked? I guess, you have to fetch that data too OR you hardcode it as you already know how many seats are there in totdal. Once you have that then your data would be something like:
Data 1 (seats reserved based on date & time):
S-1
S-2
S-5


Date 2 (based on your design that there are 6 seats in total):
S-1
S-2
S-3
S-4
S-5
S-6


Resulting Datatable you should aim to get:
seat No |  IsReserved
S-1          True
S-2          True
S-3          False
.
.
S-6          False


Now, create an outer loop of Data2 and an inner loop of Data1. Basically, you need to check what all Data2 seat numbers are in Data1. When you find a match, set isreserved flag or change the image button source as per your need.
 
Share this answer
 

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