Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

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

Avatar of 13598
13598
Flag of United States of America image

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.
Avatar of Larry Brister

ASKER

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

REmove dr.Read()
ASKER CERTIFIED SOLUTION
Avatar of 13598
13598
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
It happens   lol
Thanks...end of day tired brain!