?
Solved

add row from one datatable to another

Posted on 2007-04-03
2
Medium Priority
?
698 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
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 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

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
The viewer will learn how to synchronize PHP projects with a remote server 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.
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