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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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