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,098 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Exit the loop 4 42
How to call weather service by using asmx? 4 29
VB: Convert 2 dates to specific format 24 48
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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