Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is what i want to happen: When i select an item from the combobox the textbox will automatically be filled with data

When i select a clientName which is column 1, i want to populate the textbox with contact person which is column 2 of the Clients table.

What I have tried:

this is what i tried:

VB
 'Populate the combox with clientnames from clients '

        Try
            connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nikko Jaze Fabellon\Documents\ASRASIM.accdb")
            connection.Open()
            ds = New DataSet
            tables = ds.Tables
            dataAdapter = New OleDbDataAdapter("SELECT [ClientName] from [Clients] where [Status] = 'Active' ", connection)
            dataAdapter.Fill(ds, "Clients")
            Dim view1 As New DataView(tables(0))
            With clientNameText
                .DataSource = ds.Tables("Clients")
                .DisplayMember = "ClientName"
                .ValueMember = "ClientName"
                .SelectedIndex = 0
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.ListItems
            End With

'This is where i would enter the codes'

            With clientNameText
                .DisplayMember = "Contact Person"
                .ValueMember = "Contact Person"
                .DataSource = ds.Tables
            End With



            cPersonText.DataBindings.Add("", ds.Tables, "")
Posted
Updated 9-Mar-18 0:38am
Comments
Maciej Los 10-Feb-18 10:37am    
Contact person is not presented in second column, because your query returns only ClientName:
SELECT [ClientName] from [Clients]

1 solution

As hinted by Maciej - you are not extracting the contact person from the database. You need something more like the following (warning - I have not tested in any way)
taAdapter = New OleDbDataAdapter("SELECT [ClientName],[Contact Person] from [Clients] where [Status] = 'Active' ", connection)
.
.
.
                .DisplayMember = "ClientName"
                .ValueMember = "Client Person"
.
.
.
You can then refer to the ValueMember of the selected row to populate your textbox
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900