0

Hello, I've been working on this for three days now and I can't seem to get my listbox to populate...please help. I'm connecting to an sql database. Where am I going wrong?

Dim cmd As New SqlCommand("SELECT DISTINCT natureport FROM rates ORDER BY natureport", conn)
        Dim da As SqlDataReader

        conn.Open()
        da = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        da.Read()
        If da.HasRows Then
         ListBox1.Items.Add(da.Item("natureport"))
         End If
         da.Close()
         conn.Close()

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
8
Views
8 Years
Discussion Span
Last Post by __avd
0
Dim cmd As New SqlCommand("SELECT DISTINCT natureport FROM rates ORDER BY natureport", conn)
Dim da As SqlDataReader

conn.Open()
da = cmd.ExecuteReader(CommandBehavior.CloseConnection)
while da.Read()
   ListBox1.Items.Add(da.Item("natureport"))
end while   
da.Close()
conn.Close()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.