Hope someone could help,
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.
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.
Could anyone help out? Pete
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: " & Environment.NewLine & Environment.NewLine _
& ex.ToString)
End Try