sql读取是否为真更改图像 [英] sql read if true change image

查看:117
本文介绍了sql读取是否为真更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库

emp_no日期时间seatno
2012年5月1日凌晨5点9:00
2012年5月2日s-2上午10:00
2012年4月3日上午9:00(s-1)


我有2辆公交车在上午9点和上午10点运行

我需要检查

我的04/05/2012 9:00 am巴士座位没有s-5,然后被保留


imagebtn.url =".. jpg"

如果2012年5月5日上午10:00公交车没有预留座位,则采用相同的方式

imagebtn.url =".... jpg"

所以对于所有日期,公共汽车和所有座位


我需要页面加载的代码

如果保留,则更改图片(从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) ????

推荐答案

以上代码对您没有帮助.您有多个记录,并且始终使用一个imagebutton进行播放.

代替使用DataReader,而使用DataAdapter来获取数据.一旦数据表/数据集中有数据,然后遍历数据的每一行并相应地为该行设置imagebutton URL.

顺便说一句,在SQL查询上方,您如何知道哪些座位号尚未预订?我想,您也必须获取该数据,或者您已经对其进行硬编码,因为您已经知道在托特勒德中有多少个席位.一旦有了,那么您的数据将类似于:
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



现在,创建一个Data2的外部循环和一个Data1的内部循环.基本上,您需要检查Data1中所有的Data2座位号.找到匹配项时,请根据需要设置isreserved标志或更改图像按钮的来源.



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.


这篇关于sql读取是否为真更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆