I have a database containing a table named restaurant
. This table has columns named "time" and "tableno", and has 20 rows.
I am using this code to read the data:
Dim connString As String = "server=DESKTOP-69QA9LH\SQLEXPRESS; database=servicedb; integrated security=true"
Dim conn As New SqlConnection(connString)
Dim command As SqlCommand
Dim reader As SqlDataReader
conn.Open()
Dim query As String
query = "select time,tableno from restaurant "
command = New SqlCommand(query, conn)
reader = command.ExecuteReader
reader.Read()
Dim d1 As DateTime = ToolStripStatusLabel1.Text
Dim d2 As DateTime = reader("time")
Dim diff As Short = DateDiff(DateInterval.Minute, d2, d1)
If reader("tableno") = "2" AndAlso diff = "5" Then
Button3.BackColor = Color.LawnGreen
End If
If reader("tableno") = "2" AndAlso diff = "10" Then
Button3.BackColor = Color.LawnGreen
End If
If reader("tableno") = "2" AndAlso diff = "15" Then
Button3.BackColor = Color.LawnGreen
End If
If reader("tableno") = "1" AndAlso diff = "5" Then
Button1.BackColor = Color.Brown
End If
If reader("tableno") = "1" AndAlso diff = "10" Then
Button1.BackColor = Color.Brown
End If
If reader("tableno") = "1" AndAlso diff = "15" Then
Button1.BackColor = Color.Brown
End If
It almost works, but problem is that it only reads the 1st row in the table. I mean, when I click the button to process this code, buttons change background color based only on the first row from the table.
The row with 'tableno' 2 is the 1st row, and it changes that background color. But 'tableno' 1 is the 2nd row and I can't read this row to change background color.
How can I make it work with the other rows?