Home All Groups Group Topic Archive Search About

Help - DataAdapter.Update is not updating Access database

Author
13 Jul 2006 1:49 PM
Roy
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

Author
25 Jul 2006 12:59 AM
Long Saroeurn
OK, before u use statement daGetRecords.Update(dsGetRecords), you must use
the statement
Dim oleCmd As New OleDBCommandBuilder(daGetRecords).

Regards,

Saroeurn LONG


Show quote
"Roy" <R**@discussions.microsoft.com> wrote in message
news:CB2BA351-1663-4BC9-B3CE-C91291DEB6CE@microsoft.com...
> 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
>

AddThis Social Bookmark Button