Click here to Skip to main content
13,199,026 members (42,686 online)
Rate this:
Please Sign up or sign in to vote.
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


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


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 2-May-12 16:45pm
Updated 2-May-12 17:40pm
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. 3-May-12 0:52am

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)
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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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):

Date 2 (based on your design that there are 6 seats in total):

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 3 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100