Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 VB ASP.NET SQL , +
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 2-May-12 17:45pm
Edited 2-May-12 18:40pm
v5
Comments
amitgajjar at 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 at 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

Rate this: bad
good
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):
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.
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 3 May 2012
Copyright © CodeProject, 1999-2014
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