A better way to clone and update a table to MS Access?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newnauk
    New Member
    • Aug 2010
    • 2

    #1

    A better way to clone and update a table to MS Access?

    Hello,

    I have written an app that does a deep clone copy from an MS Access database, migrates and inserts the data to another.

    The following is my current implementation:
    ..........
    1. I'm using the strongly typed DataSet classes code-gened by VS2008 when you add an OleDb (MS Access) data source.
    2. "DestDataSe t" and SrcDataSet share the same schema.
    ..........
    Code:
    private void copy(DestDataSet dsDest, SrcDataSet dsSrc)
    {
        for (int i = 0; i < dsSource.TableA.Count; i++)
        {
            DestDataSet.TableARow rowDest = dsDest.TableA.NewTableARow();
            
            if (!((SrcDataSet.TableARow)dsSrc.TableA.Rows[i]).IsCol1Null())
               rowDest.Col1 = ((SrcDataSet.TableARow)dsSrc.TableA.Rows[i]).Col1;
    
            // repeat for Col2,..., Coln
    
            dsDest.TableA.Rows.Add(rowDest);
        }
    
        try
        {
            DestDataSetTableAdapters.TableAAdapter adpA = new DestDataSetTableAdapters.TableAAdapter();
            
            adpA.Update(dsDest.TableA);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
    Is there a better way of populating the row? I've tried using

    Code:
    foreach (SrcDataSet.TableARow row in dsSrc.TableA.Rows)
        dsDest.TableA.ImportRow(row);
    
    dsDest.AcceptChanges();
    but adpA.Update() after the loop does not seem to insert the data into the Db even though there was no runtime execption.

    Thanks!
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Why dont you just use a query? in SQL all you need to do is use one, and i believe it can be done in Access also, documentation can be found here:

    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

    Best of luck :)

    Aimee

    Comment

    Working...