how to store all items of database to combo box.
i.e. store complete column in combo box?

Like:

Using conn As New SqlConnection("connString")
    Using cmd As SqlCommand = New SqlComand("SELECT ColumnName FROM TableName", conn)
        Using reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                comboBox1.Items.Add(reader(0).ToString())
            End While
        End Using
    End Using
End Using

Hi,

A couple of ways, try this for starters:

dim DR as SQLDataReader
dim cmd as SQLCommand

cmd = New SqlCommand("SELECT Column FROM table", DBconnection)
DBconnection.Open()
DR = cmd.ExecuteReader()
If DR.HasRows Then
        Do While DR.Read()
            MyComboBox.Items.Add(DR.GetString(0))
        Loop

end if
DR.Close()

G_Waddell

Should declare DBconeection as what type?
Mycombobox is name of the combo box?

Ok I got dbconnection is connection string.but what is mycombobox?

Sure it does, you must have the correct connection string of your database. Are you sure you have one?
Which is exactly your database?

To answer on your last question, myComboBox is a reference (a reference name) to your ComboBox control.
When you create (instanitate) new comboBox control you do:
ComboBox comboBox1 = new ComboBox(); //is this example comboBox1 is same as myComboBox - its just a variable - name

But this code does C# automatically by it self when you add this control to the form. If you will look into Desiger of your form, you will see this code is there. And much more (like Size, Location, Index,...)

Hope it help explaining initial issues.

This article has been dead for over six months. Start a new discussion instead.