Note that there are some explanatory texts on larger screens.

plurals
  1. POOledbDataAdapter doesn't update table
    primarykey
    data
    text
    <p>I have a problem updating a data table. What I am doing is this:</p> <p>1) Load data from database (let's call it 'old database'</p> <p>2) Load data from other database (let's call it 'new database')</p> <p>3) Clear out all data from the new database</p> <p>4) Merge all the old data (from old database) into new database</p> <p>Here is how I have attempted to accomplish this:</p> <pre><code> string oldDatabase = this.txtOldReport.Text; string newDatabase = this.txtNewReport.Text; string backupFolder = @"C:\Planit\Report Updater\Backups"; if ( !Directory.Exists ( backupFolder ) ) { Directory.CreateDirectory ( backupFolder ); } string fullPath = Path.Combine ( backupFolder, string.Format ( @"Update Backup_{0}_{1}_{2}_{3}_{4}_{5}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) ); Directory.CreateDirectory ( fullPath ); File.Copy ( oldDatabase, Path.Combine ( fullPath, @"Old Report.mdb" ) ); File.Copy ( newDatabase, Path.Combine ( fullPath, @"New Report.mdb" ) ); OleDbConnection oldConnection = new OleDbConnection ( string.Format ( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", oldDatabase ) ); OleDbConnection newConnection = new OleDbConnection ( string.Format ( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", newDatabase ) ); OleDbCommand oldCommand = oldConnection.CreateCommand ( ); OleDbCommand newSelectCommand = newConnection.CreateCommand ( ); oldCommand.CommandText = @"SELECT * FROM Reports"; newSelectCommand.CommandText = @"SELECT * FROM Reports"; oldConnection.Open ( ); newConnection.Open ( ); DataSet oldDataset = new DataSet ( ); DataSet newDataset = new DataSet ( ); OleDbDataAdapter oldAdapter = new OleDbDataAdapter ( oldCommand ); OleDbDataAdapter newAdapter = new OleDbDataAdapter ( newSelectCommand ); OleDbCommandBuilder builder = new OleDbCommandBuilder ( newAdapter ); builder.QuotePrefix = "["; builder.QuoteSuffix = "]"; newAdapter.UpdateCommand = builder.GetUpdateCommand ( true ); newAdapter.InsertCommand = builder.GetInsertCommand ( true ); newAdapter.DeleteCommand = builder.GetDeleteCommand ( true ); oldAdapter.Fill ( oldDataset ); newAdapter.Fill ( newDataset ); newDataset.Tables [ 0 ].Rows.Clear ( ); // removed for a response below //foreach ( DataRow dr in newDataset.Tables [ 0 ].Rows ) { // dr.Delete ( ); //} foreach ( DataRow dr in oldDataset.Tables [ 0 ].Rows ) { dr.SetAdded ( ); newDataset.Tables [ 0 ].ImportRow ( dr ); } // removed for the response below //newDataset.AcceptChanges ( ); newAdapter.Update ( newDataset.Tables [ 0 ] ); oldConnection.Close ( ); newConnection.Close ( ); } </code></pre> <p>Can anyone see the problem that I have? When I call 'newAdapter.Update' nothing happens.</p> <p>Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload