Looping through multiple record in SQL database

  • Thread starter Thread starter Amr_Aly
  • Start date Start date
A

Amr_Aly

Guest
Hi everyone,

I have this code to check if one record is true or false in SQL database ... it is working fine as expected

Private Sub Availability()
Using conn As New SqlConnection(cs)
conn.Open()
Using cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandText = "select F1
from UnitA
where F1 = 1"

Using rdr As SqlDataReader = cmd.ExecuteReader()
If rdr.Read Then
MessageBox.Show("Checkbox1 is in use", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
CheckBox1.Enabled = False

If Not rdr Is Nothing Then
rdr.Close()
End If

Else
MessageBox.Show("You can use Checkbox1", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
CheckBox1.Enabled = True
End If
End Using
End Using
End Using
End Sub

But in fact i have 21 record to check them also (F1,F2,F3,.............To F21),,, the question is How can i check them by this code

I don't know how to loop through them .... I tried to search but i didn't understand so i hope anyone to explain me how to do this ..

Thanks


Regards From Egypt

Continue reading...
 
Back
Top