My project is coming along nicely thanks in part to all of your help! I have come across another bump in the road. I need to enable (up to 8) buttons based on whether or not a cell in a sql db has a 'y', 'n' or is null. I can get it to work for one button, but not 2 or more. Before I show you my code, let me give a bit more detail: My database stores info about students and grades (an numerous other things, but they don't pertain to this question). Each student must complete all eight(8) classes to graduate. In the db, I have columns labeled for each of the eight classes. If they took the class, it's a 'y' in the row. If they failed the class, it's a 'n'. If they haven't taken it yet or it's in progress, the cell has null when I view it in sql server management studio because they neither completed it nor failed it, so no data is entered yet.
I have eight(8) buttons with labels for each class. When a studentId is entered by the user and the db searched, I want the buttons enabled based on the database values. I got one to work, but that's it and I can't figure out why. Would greatly appreciate someone pointing out what is wrong in my code and point me in the correct direction.
Try
Using connection As New SqlConnection("Data Source=?;Initial Catalog=?;Persist Security Info=True;User ID=?;Password=?")
connection.Open()
Dim dt As New DataTable
Dim ds As New DataSet
Dim da As New SqlDataAdapter
ds.Tables.Add(dt)
da = New SqlDataAdapter("select g1, g2, af1, af2, af3, pp1, pp2, pp3 from student_info where studentId = '" & stunumtxtbox.Text & "'", connection)
Dim count = da.Fill(dt)
If count = 1 Then
G1Button.Enabled = True
End If
If count = 2 Then
G2Button.Enabled = True
End If
If count = 3 Then
AF1Button.Enabled = True
End If
If count = 4 Then
AF2Button.Enabled = True
End If
If count = 5 Then
AF3Button.Enabled = True
End If
If count = 6 Then
PP1Button.Enabled = True
End If
If count = 7 Then
PP2Button.Enabled = True
End If
If count = 8 Then
PP3Button.Enabled = True
End If
End Using
Catch se As SqlException
MsgBox(se.Message)
Finally
End Try
Thank you in advance!