VB.NET Using Combobox to pull data from MS Access DataBase and fill the textbox from Data

2.8k views Asked by At

VB.NET Using Combobox to retrieve data from MS SQL DataBase and fill a textbox with the data

I am working on a VB.Net project in Visual Studio 2013 project. I want a combobox to retrieve data from ms access database and fill a textbox

I have a MS Access DB Named DataDB and i have a Form Named Form1 with a Combobox on it is Named cboData and three textBox Named txtName, txtPhone and txtAddress. The DataDB holds my customer Name, Phone and Address.

I want to use the ComboBox to access the DataDB and use the value to populate three textBox Named txtName, txtPhone and txtAddress in the form(load event)

1

There are 1 answers

14
Aousaf Rashid On

It is really unclear what your motive is.But as far as i think,u want to populate a combo box from an access database(maybe).Then you can try this

'create a connection string named con

Public sub MyForm_Load

Dim cmd as new OleDbCommand("Select * from [table name here-avoid brackets 
 if required]",con)

Dim adapter as new OleDbDataadapter(cmd)

Dim table as new datatable

adapter.fill(table)

ComboBox1.DataSource = table
ComboBox1.DisplayMember = table.Columns(3).ToString 'you can use column name or even row

Now, to add text to the textbox from the combo box, try :

Public Sub ComboBox1_IndexChanged

Textbox1.tex=Combobox1.text

If you think this is not what you want, then please clarify your needs

Datatable to textbox

 For i = 0 To table.Rows.Count - 1
        textbox1.Text = table.Rows(i)(3).value.ToString
    Next