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
Solved

add row from one datatable to another

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.

790 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