title: Vb.net SQL bulk insert/copy
body: <p>Hope someone could help,</p>
  
  <p>Background: Got an old machine that puts data into an MS access file and we need to import the table into an SQL table, the access database keeps a rolling 3 days of data and then deletes the older data, the idea is to run a task every morning to insert the new records to sql, ignore existing so we can build a graph over the year.</p>
  
  <p>I've extracted data from MS access into a Datatable called "table" and created the column names in an SQL table which matches, i've read about SQL Bulkcopy but all of the samples i've seen are in C# but any code converters error out and im not 100% that they'll do what im after.</p>
  
  <p>Could anyone help out?
  Pete</p>
  
  <pre><code>Dim count As Integer = 0
      Dim table As DataTable = New DataTable
      Dim accConnection As New OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0; Data Source='C:\Machine.mdb';User Id=admin; Password=;")
      Dim sqlConnection As New SqlClient.SqlConnection("Data Source=10.75.24.94;Initial Catalog=CTData;User ID=sql;Password=")
      Try
          'Import the Access data
          accConnection.Open()
          Dim accDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM Slot_Vision_Counters_table", accConnection)
          accDataAdapter.Fill(table)
          accConnection.Close()
          'Export to MS SQL
          For Each row As DataRow In table.Rows
              row.SetAdded()
              count = count + 1
          Next
  
  
  Code for inserting the data to SQL?
  
  
      Catch ex As Exception
          If accConnection.State = ConnectionState.Open Then
              accConnection.Close()
          End If
          If sqlConnection.State = ConnectionState.Open Then
              sqlConnection.Close()
          End If
          MessageBox.Show("Import failed with error: " &amp; Environment.NewLine &amp; Environment.NewLine _
          &amp; ex.ToString)
      End Try
  </code></pre>