Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27388

Populate text box with a combobox selection. VS2012 and Access

$
0
0
I'm using the following code to populate a combo box from an access database:

Code:

  Dim cm As New OleDbCommand("select * from employee", m_cn)
        Dim dr As OleDbDataReader = cm.ExecuteReader
        While dr.Read
            cboEmployeeName.Items.Add(dr(0).ToString)
        End While

        Dim cm1 As New OleDbCommand("select * from workcenter", m_cn)
        Dim dt1 As New DataTable

        Dim dr1 As OleDbDataReader = cm1.ExecuteReader
        While dr1.Read
            cboworkcenter.Items.Add(dr1(0).ToString)
        End While
        dr.Close()
        dr1.Close()

I want to fill in some text boxes with the selection of the combobox. The database has 3 columns. The comboBox is populated by the first column and I want to fill the textboxs with column 2 and 3. I have tried databindings but I keep getting error messages when running the program. I tried:
Code:

txtemployeeID.databinding.add("text", , "Value Stream")
I have tried several things in the second argument but nothing seams to work.

1. Can I use this code inside a while statement to bind the textbox?
2. Do I need to declare a new datatable and data adapter for each while statement?

Thanks in advance.

Viewing all articles
Browse latest Browse all 27388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>