DataTable Update Access database
-
I am reading a table in from one access Database and storing it in a DataTable(or DataSet if easier) I then want to update an empty table in another database with the data in the DataTable. the two tables have the same fields I know I can read the DataTable row by row and add the data to the 2nd database but I am wondering if there is an easier shorter way. here is the code I am currently working on, (not sure that it will work all of the DataTable/DataSet examples I have found only are working with pulling data and updating from a single database. DataTable HashTable = new DataTable(); Classes.SeedsDB seed = new Classes.SeedsDB(); seed.GetHashTable(ref seedDBPath, ref HashTable); //Opens 1st Database and stores the Table in HashTable OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM BadHashTable",MAconn); OpenAccessDB(); //Opens 2nd Database holds connection string that works in other Methods in the class OleDbCommandBuilder Cmdbld = new OleDbCommandBuilder(OSAppsAdapter); Adapter.Update(HashTable); CloseAccessDB();
-
I am reading a table in from one access Database and storing it in a DataTable(or DataSet if easier) I then want to update an empty table in another database with the data in the DataTable. the two tables have the same fields I know I can read the DataTable row by row and add the data to the 2nd database but I am wondering if there is an easier shorter way. here is the code I am currently working on, (not sure that it will work all of the DataTable/DataSet examples I have found only are working with pulling data and updating from a single database. DataTable HashTable = new DataTable(); Classes.SeedsDB seed = new Classes.SeedsDB(); seed.GetHashTable(ref seedDBPath, ref HashTable); //Opens 1st Database and stores the Table in HashTable OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM BadHashTable",MAconn); OpenAccessDB(); //Opens 2nd Database holds connection string that works in other Methods in the class OleDbCommandBuilder Cmdbld = new OleDbCommandBuilder(OSAppsAdapter); Adapter.Update(HashTable); CloseAccessDB();
I prefer to just use a DataReader to read from one and copy to another. Simply using the Update won't work, as you've found. The rows have the wrong status for that, you'd have to change their status. It's kind of the opposite of AcceptChanges. I'm not sure you can, I haven't tried it. I'll have a quick look. [Later] See DataRow.SetAdded Method Changes the Rowstate() of a DataRow to Added.
modified on Monday, February 9, 2009 11:45 PM
-
I prefer to just use a DataReader to read from one and copy to another. Simply using the Update won't work, as you've found. The rows have the wrong status for that, you'd have to change their status. It's kind of the opposite of AcceptChanges. I'm not sure you can, I haven't tried it. I'll have a quick look. [Later] See DataRow.SetAdded Method Changes the Rowstate() of a DataRow to Added.
modified on Monday, February 9, 2009 11:45 PM