title: Bulk Insert From DataTable to Access Database
body: <p>Already have the DataTable populated but need to dump its entire table contents into an Access database. </p>
  
  <pre><code>Using (conn)
      If conn.State &lt;&gt; ConnectionState.Open Then conn.Open()
      Dim adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM " &amp; sMdbTableName, conn)
      adapter.InsertCommand = New OleDbCommand("INSERT INTO " &amp; sMdbTableName &amp; " SELECT * FROM " &amp; sMdbTableNameSource &amp; ";", conn)
      adapter.TableMappings.Add(sMdbTableName, ds.Tables.Item(sMdbTableNameSource).ToString)
      adapter.Update(ds.Tables.Item(sMdbTableNameSource))
  End Using
  </code></pre>
  
  <p>Im trying to do something like this but no errors and no data added. Need the best performing way.</p>
  
  <p>Thanks</p>
  
  <p>Edit:</p>
  
  <p>Updated code is slow as heck and need a bulk type of access import: </p>
  
  <pre><code>        Using (conn)
              If conn.State &lt;&gt; ConnectionState.Open Then conn.Open()
              Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
              adapter.InsertCommand = New OleDbCommand("INSERT INTO " &amp; sMdbTableName &amp; "(Field1, Field2, Field3, Field4, Field5) VALUES(@Field1, @Field2, @Field3, @Field4, @Field5);", conn)
              adapter.InsertCommand.Parameters.Add("Field1", OleDbType.VarChar, 16, "Field1")
              adapter.InsertCommand.Parameters.Add("Field2", OleDbType.VarChar, 16, "Field2")
              adapter.InsertCommand.Parameters.Add("Field3", OleDbType.VarChar, 16, "Field3")
              adapter.InsertCommand.Parameters.Add("Field4", OleDbType.VarChar, 16, "Field4")
              adapter.InsertCommand.Parameters.Add("Field5", OleDbType.VarChar, 16, "Field5")
              adapter.TableMappings.Add(sMdbTableName, ds.Tables.Item(sMdbTableNameSource).ToString)
              adapter.Update(ds.Tables.Item(sMdbTableNameSource))
          End Using
  </code></pre>