Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Adding fields from a database to a listbox (http://www.go4expert.com/forums/adding-fields-database-listbox-t25159/)

bouki 5Mar2011 09:30

Adding fields from a database to a listbox
 
I want to add all the Records in my database in a list box (Book name), However nothing is adding to the listbox

Code:

cmd.Connection = cn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = " select BookName from Book "
        rdr = cmd.ExecuteReader
        Do While rdr.Read
            cbdvuser.Items.Add(rdr.Item("BookName"))
        Loop
        cn.Close()


virxen 6Mar2011 05:54

Re: Adding fields from a database to a listbox
 
inside the while loop
add a msgbox command to show you what it reads


something like this i mean
Code:

..........
 Dim reader As SqlDataReader
  reader = Command.ExecuteReader()
  While reader.Read()
    MsgBox(reader.Item(0))
  End While
  reader.Close()
.........


bouki 6Mar2011 08:58

Re: Adding fields from a database to a listbox
 
Thanks alot


All times are GMT +5.5. The time now is 09:33.