Solved

add row from one datatable to another

Posted on 2007-04-03
2
695 Views
Last Modified: 2013-12-16
I am trying to add a datarow from one table to another, but I am getting the error "This row already belongs to another table."

        For Each dr As DataRow In dsImport.Tables(0).Rows
                failDS.Tables(0).Rows.Add(dr)
        Next

How do I do this?  Do I need to make a copy?
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18847299
Try

    failDS.Tables(0).ImportRow(dr)

Roger
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 18849815
datarow always "belongs" to a datatable, and cannot exist independently.
So once added to a table, the same row cannot be added again to another table.

You can actually use the following statement for what you want to do:

dt2.Rows.Add(dr1.ItemArray)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

724 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