Search code examples
vb.netms-accesscomboboxmultiple-columnsitems

Fill Combobox with combined columns access database


How can I combine the columns "Firstname" "Lastname" from my access database "contacts.accdb" filling combobox?? I have already loaded the dataset +datagridview into another form in the project..


Solution

  • A simple but complete example :

    Dim con as New OledbConnection = connectionstringhere
    Dim cmd as New OleDbCommand("Select * from tablenamehere",con)
    Dim dr as OledbDataReader=cmd.ExecuteReader
    While dr.read
    Dim FnameAndLname as string = dr(0).ToString + " " + dr(1).ToString 'Assuming the FirstName is the 1st and the LastName is the 2nd Column of the table
    MyConboBox.Items.Add(FnameAndLname)
    End while
    

    Hope this helps :)