Checkbox list

I have a radList that uses checkboxes.

My attached code sets everything to checked EXCEPT the first item on the returned data.  It always skips the first one.
If dR.HasRows Then
            Dim j As Integer
            ' Check only those which match with database
            If dR.HasRows Then
                Do While dR.Read()
                    For j = 0 To RadListBox1.Items.Count - 1
                        If RadListBox1.Items(j).Value = dR("fips") Then
                            RadListBox1.Items(j).Checked = True
                        End If
                    Next
                Loop
            End If
        Else

Open in new window

lrbristerAsked:
Who is Participating?
 
13598Connect With a Mentor Commented:
Protected Sub selectLinks(ByVal id As Integer)
        Dim objConn As SqlConnection
        objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
        Dim oCom As SqlCommand
        oCom = New SqlCommand
        oCom.Connection = objConn
        oCom.CommandText = "dbo.sp_parse_list"
        oCom.CommandType = CommandType.StoredProcedure
        oCom.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = id
        oCom.Parameters.Add(New SqlParameter("@col", SqlDbType.VarChar, 20)).Value = "fips"
        oCom.Parameters.Add(New SqlParameter("@tbl", SqlDbType.VarChar, 20)).Value = "court_Runners"
        objConn.Open()
        Dim dR As SqlDataReader
        dR = oCom.ExecuteReader()
                If dR.HasRows Then
 Dim j As Integer
            ' Check only those which match with database

                Do While dR.Read()
                    For j = 0 To RadListBox1.Items.Count - 1
                        If RadListBox1.Items(j).Value = dR("fips") Then
                            RadListBox1.Items(j).Checked = True
                        End If
                    Next
                Loop
            End If
           End Sub
0
 
13598Commented:
What is the line right before your first 'If dR.HasRows Then'  that you posted?
Are you reading the dr I suppose?
Then your Do while dr.read brings in the second record since you read once to find out if there are any rows. You skipped the first record.
0
 
lrbristerAuthor Commented:
13598
The full sub is attached
Protected Sub selectLinks(ByVal id As Integer)
        Dim objConn As SqlConnection
        objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
        Dim oCom As SqlCommand
        oCom = New SqlCommand
        oCom.Connection = objConn
        oCom.CommandText = "dbo.sp_parse_list"
        oCom.CommandType = CommandType.StoredProcedure
        oCom.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = id
        oCom.Parameters.Add(New SqlParameter("@col", SqlDbType.VarChar, 20)).Value = "fips"
        oCom.Parameters.Add(New SqlParameter("@tbl", SqlDbType.VarChar, 20)).Value = "court_Runners"
        objConn.Open()
        Dim dR As SqlDataReader
        dR = oCom.ExecuteReader()
        dR.Read()
        If dR.HasRows Then
            Dim j As Integer
            ' Check only those which match with database
            If dR.HasRows Then
                Do While dR.Read()
                    For j = 0 To RadListBox1.Items.Count - 1
                        If RadListBox1.Items(j).Value = dR("fips") Then
                            RadListBox1.Items(j).Checked = True
                        End If
                    Next
                Loop
            End If
        Else
        End If
    End Sub

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
13598Commented:
REmove dr.Read()
0
 
lrbristerAuthor Commented:
13598:
Oh man...that is REALLY embarrassing!

As soon as I copied my code into the EE and submitted I saw it.

End of day brain gas!
Thanks
0
 
13598Commented:
It happens   lol
0
 
lrbristerAuthor Commented:
Thanks...end of day tired brain!
0
All Courses

From novice to tech pro — start learning today.