Moving data between Access databases

G

Guest

I have two Access databases: one has records, the other only has blank
tables. I want to copy records to the empty database. I am using a
DataAdaptor and a DataSet for the transfer. My code works for for editing
records or using the Row.ADD() method to append records.

To transfer the records, I have tried the code shown below and variations of
it. The code does not cause an exception but does not transfer the records
either. What code structure should I use for this task?

Dim sSQL As String = "Select * From Publishers"
Dim oleConnLoad As New
OleDb.OleDbConnection(gsConnectionStringLoad)
Dim oleConnSave As New
OleDb.OleDbConnection(gsConnectionStringSave)
Dim oleDALoad As New OleDb.OleDbDataAdapter(sSQL, oleConnLoad)
Dim oleDASave As New OleDb.OleDbDataAdapter(sSQL, oleConnSave)
Dim oDSLoad As New DataSet
Dim oDSSave As New DataSet
oleDALoad.Fill(oDSLoad, "Publishers")
oleDASave.Fill(oDSSave, "Publishers")

Dim oCmdBuilder As New OleDb.OleDbCommandBuilder(oleDASave)
oCmdBuilder.QuotePrefix = "["
oCmdBuilder.QuoteSuffix = "]"
oleDASave.InsertCommand = oCmdBuilder.GetInsertCommand
oleDASave.DeleteCommand = oCmdBuilder.GetDeleteCommand
oleDASave.UpdateCommand = oCmdBuilder.GetUpdateCommand
oDSSave.Merge(oDSLoad)
oleDASave.Update(oDSSave, "Publishers")
 
T

Thomas Wenning

genojoe said:
I have two Access databases: one has records, the other only has blank
tables. I want to copy records to the empty database. I am using a
DataAdaptor and a DataSet for the transfer. My code works for for editing
records or using the Row.ADD() method to append records.

To transfer the records, I have tried the code shown below and variations of
it. The code does not cause an exception but does not transfer the records
either. What code structure should I use for this task?

Dim sSQL As String = "Select * From Publishers"
Dim oleConnLoad As New
OleDb.OleDbConnection(gsConnectionStringLoad)
Dim oleConnSave As New
OleDb.OleDbConnection(gsConnectionStringSave)
Dim oleDALoad As New OleDb.OleDbDataAdapter(sSQL, oleConnLoad)
Dim oleDASave As New OleDb.OleDbDataAdapter(sSQL, oleConnSave)
Dim oDSLoad As New DataSet
Dim oDSSave As New DataSet
oleDALoad.Fill(oDSLoad, "Publishers")
oleDASave.Fill(oDSSave, "Publishers")

Dim oCmdBuilder As New OleDb.OleDbCommandBuilder(oleDASave)
oCmdBuilder.QuotePrefix = "["
oCmdBuilder.QuoteSuffix = "]"
oleDASave.InsertCommand = oCmdBuilder.GetInsertCommand
oleDASave.DeleteCommand = oCmdBuilder.GetDeleteCommand
oleDASave.UpdateCommand = oCmdBuilder.GetUpdateCommand
oDSSave.Merge(oDSLoad)
oleDASave.Update(oDSSave, "Publishers")
Hi,

i use this
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3514&lngWId=10
and read this xml-file into the second access database.

Greeting

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top