Solved

C# -- trying to add dataset row from one dataset to another -- ERROR: This row already belongs to another table.

Posted on 2006-06-21
1
1,099 Views
Last Modified: 2012-06-21
I have a dataset with lets say ten rows.  I am trying to loop through the dataset and find those that have the first column equal to 'ABC' and add those to another dataset.  Refer to my code below.  I receive the error 'This row already belongs to another table'.   I need to create a separate dataset as I am needing to use the data somewhere else.

foreach(DataRow dr in dsAll.Tables[0].Rows)
{
if (dr[0].ToString() == "ABC")
{
    dsQuery.Tables[0].NewRow();
    dsQuery.Tables[0].Rows.Add(dr);
}
}

Thanks
0
Comment
Question by:vandy02
1 Comment
 
LVL 11

Accepted Solution

by:
anyoneis earned 500 total points
ID: 16957419
foreach(DataRow dr in dsAll.Tables[0].Rows)
{
if (dr[0].ToString() == "ABC")
{
    dsQuery.Tables[0].Rows.Add(dr.ItemArray)
}
}


David
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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