title: How to input multiple ComboBox values into Access Database from Visual Studio via VB.net
body: <p>With the current code that I am running no errors occur, but no data gets added to the Microsoft Access DB.  It only uploads the data to the DB if 2 or less of the ComboBoxes are included in the code.  This has me very confused.  I have tried ComboBox1.SelectedItem.ToString, ComboBox1.SelectedItem.Text, and ComboBox1.Text and similar issues arise for all of them.  Any ideas?</p>
  
  <pre><code>Imports System.Data.OleDb
  
  Public DefineDataFile As String
  Dim provider As String
  Dim dataFile As String
  Dim connString As String
  Dim myConnection As OleDbConnection = New OleDbConnection
  
  
      provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
      dataFile = "XXXXXXXXXXXXX.mdb"
      connString = provider &amp; dataFile
      myConnection.ConnectionString = connString
      myConnection.Open()
  
      Dim str As String
      str = "INSERT INTO [Panels/Equipment] ([Panel/Equipment Name], [Machine Name], [Panel/Equipment #], [Type], [Functional Location], [Facility], [Category], [Lifetime Cost Savings], [Hours Per Day], [Days Per Week], [Weeks Per Year], [Description], [Environmental Condition], [Environmental Option], [Environmental Finding], [Heating/Cooling Condition], [Heating/Cooling Option], [Heating/Cooling Finding], [Wiring Condition], [Wiring Option], [Wiring Finding], [Machines ID])"
      str += "SELECT ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,[Machines].[Machines ID]"
      str += "FROM [Machines] WHERE [Machines].[Machine Name] = ? "
  
      Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
      cmd.Parameters.Add(New OleDbParameter("Panel/Equipment Name", CType(TextBox_Name.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Machine Name", CType(TextBox_Machine.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Panel/Equipment #", CType(TextBox_PENum.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Type", CType(ComboBox_Type.SelectedItem.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Functional Location", CType(TextBox_FunctionalLocation.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Facility", CType(TextBox_Facility.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Category", CType(ComboBox_Category.SelectedItem.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Lifetime Cost Savings", CType(TextBox_LifetimeCostSavings.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Hours Per Day", CType(TextBox_HoursPerDay.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Days Per Week", CType(TextBox_DaysPerWeek.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Weeks Per Year", CType(TextBox_WeeksPerYear.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Priority", CType(ComboBox_Priority.SelectedItem.Text, String)))
      cmd.Parameters.Add(New OleDbParameter("Description", CType(TextBox_Description.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Environmental Condition", CType(ComboBox_EC.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Environmental Option", CType(ComboBox_EO.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Environmental Finding", CType(ComboBox_EF.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Heating/Cooling Condition", CType(ComboBox_HCC.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Heating/Cooling Option", CType(ComboBox_HCO.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Heating/Cooling Finding", CType(ComboBox_HCF.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Wiring Condition", CType(ComboBox_WC.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Wiring Option", CType(ComboBox_WO.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Wiring Finding", CType(ComboBox_WF.SelectedItem.Text, String)))
   *  cmd.Parameters.Add(New OleDbParameter("Machine ID", CType(ComboBox_Machine.SelectedItem.ToString, String)))
     Try
          cmd.ExecuteNonQuery()
          cmd.Dispose()
          myConnection.Close()
          MsgBox("Panel/Equipment Successfully Added")
  
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
      myConnection.Close()
  </code></pre>