Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataTable Update Access database

DataTable Update Access database

Scheduled Pinned Locked Moved C#
databaseannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Planker
    wrote on last edited by
    #1

    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();

    P 1 Reply Last reply
    0
    • P Planker

      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();

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • P PIEBALDconsult

        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

        P Offline
        P Offline
        Planker
        wrote on last edited by
        #3

        Thanks for the help I ended up using the DataTableReader and got it working.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups