title: How to populate master detail combobox in VB?
body: <p>I have two <strong>Comboboxes</strong> with Master Detail Relationship Table <strong>Bank</strong> and <strong>Branch</strong></p>
  <p><a href="https://i.stack.imgur.com/hatX2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hatX2.png" alt="enter image description here" /></a></p>
  <p>My VB code behind:-</p>
  <pre><code>Public Class Form1
  
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          
          Using con As New OleDbConnection(&quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\New\Test.accdb&quot;)
  
  
  
              Using cmd As New OleDbCommand(&quot;Select Bank, ID from Bank&quot;, con)
                  Dim da As New OleDbDataAdapter(cmd)
                  Dim dt As New DataTable
  
                  da.Fill(dt)
  
  
                  ComboBox1.DataSource = dt
  
                  ComboBox1.DisplayMember = &quot;Bank&quot;
                  ComboBox1.ValueMember = &quot;ID&quot;
                  ComboBox1.Text = &quot;Select&quot;
              End Using
          End Using
      End Sub
  
      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
          Dim bankId = ComboBox1.SelectedValue.ToString
          Using con As New OleDbConnection(&quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\New\Test.accdb&quot;)
              Using branch_cmd As New OleDbCommand(&quot;Select Branch from Branch where Bank_id ='&quot; &amp; bankId &amp; &quot;'&quot;, con)
                  Dim da As New OleDbDataAdapter(branch_cmd)
                  Dim dt As New DataTable
                  da.Fill(dt)
                  ComboBox2.DataSource = dt
                  ComboBox2.DisplayMember = &quot;Bank&quot;
                  ComboBox2.ValueMember = &quot;ID&quot;
              End Using
          End Using
      End Sub
  End Class
  </code></pre>
  <p>I want to populate in second combo box based on first combobox selected value, but the code got error on
  ComboBox1_SelectedIndexChanged function:</p>
  <p><a href="https://i.stack.imgur.com/f7C6j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f7C6j.png" alt="enter image description here" /></a></p>
  <p>And, from debugging the branch_cmd sql is:</p>
  <pre><code>Select Branch from Branch where Bank_id ='System.Data.DataRowView'
  </code></pre>