Copy Datasource from one DataTable to another in VB.Net 2005

Posted on 2006-06-02
Last Modified: 2006-11-18
Hi Experts,

My Test project includes the following:

"frmBids" = Parent form
"frmBidsDetail" = Child Datagridview

"frmBidImport" = Popup Datagridview with existing data in table "tblBidImport"

I need help on copying the data from "frmBidImport" datatable to the Child Datagridview "frmBidsDetail" datatable and updating to the database.

I have tried this several different ways. I get the data to the Child Datagridview OK, but I can't get the Child to synchronize with the Parent for updating.

I find that if I key the data into the Child Datagridview, the Parent/Child relationship works fine.
But if the data is imported direct to the Child database table the Child will not update with the Parent.

A simple walkthrough would sure help as I am a beginner.



Question by:dave_sky
    LVL 34

    Accepted Solution

    How is the data being "imported direct to the Child database table"?  I'm not sure from your description if this is the problem, but when you "import" rows from one datatable to another they are carried over lock, stock and barrel.  Specifically, their .RowState flags are unchanged.  That's important because TableAdapters (or DataAdapters) rely on the .RowState flags to know what updates need doing.  When you "key the data into the Child Datagridview" that creates a new record in the datatable with a .RowState of Added: the adapter knows that it has to be inserted into the database on an update.  But when you fill "tblBidImport" the .RowState of each of its records will be Unchanged.  If you then just "import" those into the Child database table, the .RowStates will still be Unchanged.  And when the adapter is asked to update from the Child database table it will do nothing to them.

    Here's a link to another question.

    I've just posted in that code which shows how to copy rows from one table to another to avoid that problem.  Although - it looks like you are on VB.NET 2005, so there might be an alternative route, using .Import and .SetAdded - I suggest that, if the above description looks like it might be your problem, you give that solution a try.


    Author Comment

    How's that for service?

    I accepted the comment before I got the email that your comment was posted...

    Thanks for your help!

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now