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

Posted on 2006-06-02
Medium Priority
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

Sancler earned 2000 total points
ID: 16820890
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

ID: 16820936
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

864 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