Just want to ask why this wont work for me?
I'm trying to bring back data for booking system (or something which like that).
The problem is that it only go to only one if statement and ignore the second one.
Using VB.net and trying to connect to MySQL database.
Thanks all...
Petr
thanks for answers guys i will try all the problem is that if its not = to let say Monday then it should make the color of the check-box white.
I will try the select case and see.
I did some changes add there checkbox lists that it make it easier. The problem is to clear the checkbox on different days.
CheckBoxListMon.BackColor = Drawing.Color.White
CheckBoxListMon.Enabled = True
CheckBoxListMon.ClearSelection()
This make the checkbox enabled and not selected but I still cant can't click on them they are disabled.
Anyone have some idea?
Try
strQuery = "SELECT BookingDate, BookingTime,BookRegUserID,Booked FROM bookings"
MySQLCmd = New MySqlCommand(strQuery, dbCon)
dbCon.Open()
DR = MySQLCmd.ExecuteReader
While DR.Read
bookDate = DR.Item("BookingDate")
bookTime = DR.Item("BookingTime")
bookRegID = DR.Item("BookRegUserID")
booked = DR.Item("Booked")
Select Case True
Case bookDate = lblMonday.Text And CheckBoxListMon.Items.FindByValue(test) IsNot Nothing
CheckBoxListMon.Items.FindByValue(bookTime).Enabled = False
CheckBoxListMon.Items.FindByValue(bookTime).Selected = True
CheckBoxListMon.Items.FindByValue(bookTime).Attributes.Add("Style", "color: red;")
Case bookDate = lblTuesday.Text And CheckBoxListTue.Items.FindByValue(test) IsNot Nothing
CheckBoxListTue.Items.FindByValue(bookTime).Enabled = False
CheckBoxListTue.Items.FindByValue(bookTime).Selected = True
CheckBoxListTue.Items.FindByValue(bookTime).Attributes.Add("Style", "color: red;")
End While
DR.Close()
dbCon.Close()
Catch ex As Exception
End Try
I think Isee the problem now. You dont want to flip the comboboxes back if they do not match. Lets say you have Monday Tuesday being returned in your result set. The first row will flip monday to true and tuesday to false, the second will set monday to false - which I do not think you want - and set tuesday to true, leaving everything being decided by the last row. The answer is to set them all to false before processing the rows, and only set to true if you get a match, otherwise ignore it.
CbMon10.BackColor = Drawing.Color.White
CbMon10.Checked = False
CbMon10.Enabled = True
CbTue10.BackColor = Drawing.Color.White
CbTue10.Checked = False
CbTue10.Enabled = True
While DR.Read
bookDate = DR.Item("BookingDate")
bookTime = DR.Item("BookingTime")
bookRegID = DR.Item("BookRegUserID")
booked = DR.Item("Booked")
Select Case True
Case bookDate = lblMonday.Text And bookTime = CbMon10.Text
CbMon10.BackColor = Drawing.Color.Red
CbMon10.Checked = True
CbMon10.Enabled = False
Case bookDate = lblTuesday.Text And bookTime = CbTue10.Text
CbTue10.BackColor = Drawing.Color.Red
CbTue10.Checked = True
CbTue10.Enabled = False
End Select
End While