Link to home
Start Free TrialLog in
Avatar of vandy02
vandy02Flag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of anyoneis
anyoneis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial