G
Guest
Hi all,
I'm trying to update a table in an Access database with the records in a
table from another Access database that both tables have exact schema. Table
one has about 10,000 records and table two usually has 10-20 records.
Here is the sample code that works for the most part, but not for the place
that changes need to be sent back to the database:
'Table one
Dim daGetRecords As New OleDbDataAdapter
Dim dsGetRecords As New DataSet
daGetRecords.SelectCommand = New OleDbCommand(strSQL, cn)
daGetRecords.Fill(dsGetRecords)
'Table 2 from different database, using the same sql statement different
conection
Dim daRecords As New OleDbDataAdapter
Dim dsRecords As New DataSet
daRecords.SelectCommand = New OleDbCommand(strSQL, cn2)
daRecords.Fill(dsRecords)
'Here I assign primary keys of two tables
'
'
'And merge rows
Dim dr As DataRow
For Each dr In dsRecords.Tables(0).Rows
Dim drow(0) As DataRow
drow(0) = dr
dsGetRecords.Merge(drow)
Next
' I've checked and dsGetRecords has been updated correctly.
' I'm ready to send changes back to the database.
' And this is the place that I'm having problem
daGetRecords.Update(dsGetRecords)
Please comment:
1. Why update method of dataadapter is not updating database?
2. Is there a better way to do the whole process?
Thanks in advance,
Roy
I'm trying to update a table in an Access database with the records in a
table from another Access database that both tables have exact schema. Table
one has about 10,000 records and table two usually has 10-20 records.
Here is the sample code that works for the most part, but not for the place
that changes need to be sent back to the database:
'Table one
Dim daGetRecords As New OleDbDataAdapter
Dim dsGetRecords As New DataSet
daGetRecords.SelectCommand = New OleDbCommand(strSQL, cn)
daGetRecords.Fill(dsGetRecords)
'Table 2 from different database, using the same sql statement different
conection
Dim daRecords As New OleDbDataAdapter
Dim dsRecords As New DataSet
daRecords.SelectCommand = New OleDbCommand(strSQL, cn2)
daRecords.Fill(dsRecords)
'Here I assign primary keys of two tables
'
'
'And merge rows
Dim dr As DataRow
For Each dr In dsRecords.Tables(0).Rows
Dim drow(0) As DataRow
drow(0) = dr
dsGetRecords.Merge(drow)
Next
' I've checked and dsGetRecords has been updated correctly.
' I'm ready to send changes back to the database.
' And this is the place that I'm having problem
daGetRecords.Update(dsGetRecords)
Please comment:
1. Why update method of dataadapter is not updating database?
2. Is there a better way to do the whole process?
Thanks in advance,
Roy