[OleDB] Combobox mit Key/Value Paaren aus einer Datenbank füllen

Dim DB_OleDBCommand As New System.Data.OleDb.OleDbCommand
Dim DB_OleDBDataAdapter As New System.Data.OleDb.OleDbDataAdapter
Dim dsFuel As New DataSet

DB_OleDBCommand.Connection = frmMain.DB_OleDBConnection

dsFuel.Clear()
DB_OleDBCommand.CommandText = "SELECT ID, Name FROM Users ORDER BY Name"

DB_OleDBDataAdapter.SelectCommand = DB_OleDBCommand
DB_OleDBDataAdapter.Fill(dsFuel)

With cbFuel
    .Items.Clear()
    .DataSource = dsFuel.Tables(0)
    .DisplayMember = "Name"
    .ValueMember = "ID"
End With

' Key/Value Paare auslesen/setzen

Dim Key As String = cbFuel.SelectedValue.ToString() ' auslesen
cbFuel.SelectedValue = 10 ' setzen

Schreibe einen Kommentar