existsman
existsman

Reputation: 39

put the contents of the database to a combobox

I am using vb.net and mysql as the database.

I have created a field containing the abbreviations of words. My vb.net form provides a combobox which I want to connect to the field abbreviation. I want to configure the combobox so that when clicked, all the acronyms that exist in the database appear in the combobox.

Any suggestions on how I can get started?

Upvotes: 1

Views: 1648

Answers (1)

slandau
slandau

Reputation: 24052

Something like this:

Dim conn As New SqlConnection(connString)

Dim strSQL As String = "SELECT * FROM abbreviations"
Dim da As New SqlDataAdapter(strSQL, conn)
Dim ds As New DataSet
da.Fill(ds, "abbreviations")

With ComboBox1
    .DataSource = ds.Tables("abbreviations")
    .DisplayMember = "abbreviation_name"
    .ValueMember = "abbreviation_id"
    .SelectedIndex = 0
End With

Should give you the right idea to get started.

Upvotes: 1

Related Questions