Solved

add row from one datatable to another

Posted on 2007-04-03
2
689 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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

707 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

13 Experts available now in Live!

Get 1:1 Help Now