0

I am getting stuck on this problem. It seems simple but for some reason im having trouble.

Here is what I have of the following:

 Try
        cn = New OleDbConnection("Provider=microsoft.Jet.OLEDB.4.0;Data Source=G:\Sean\BMSBonder3_0.mdb;")
        cn.Open()
        str = "Select Distinct BonderIdentifier From [Session]"
        cmd = New OleDbCommand(str, cn)
        dr = cmd.ExecuteReader

        dr.Read()
        If dr.Item(0).ToString <> "" Then
            ListBox1.Items.Add(dr.Item(0))
        End If

        cn.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

This works to get only one of the values. Actually the last. how can i get all of them?

Sorry for the newb question. Searching didnt help too much.

1 Answer 1

2

You need to use a While loop to repeatedly execute your code until dr.Read() returns False.
For example:

While dr.Read()
    If dr.Item(0).ToString <> "" Then
        ListBox1.Items.Add(dr.Item(0))
    End If
Wend
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.