Home > Forum > ASP.NET > DataTable already belongs to another DataSet

DataTable already belongs to another DataSet

by Narain_Siddharth   on May 17, 2011   Category: ASP.NET  |  Views: 903    |  Points: 5   |  Silver 
  Reply
Displaying error like "DataTable already belongs to another DataSet" when i trying to add datatable to another dataset. please provide the solution for this.

DataTable dt    = new DataTable();
DataSet dsValue = new DataSet();
dsValue.Tables.Add(dt);
DataSet dsResult = new DataSet();
DataTable dttemp = dsValue.Tables[0];
dsResult.Tables.Add(dttemp);



Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :DataTable already belongs to another DataSet   
by Narain_Siddharth
on May 19 2011 2:07AM
Points : 10
Silver 
i resolved this error. the error message itself saying datatable is belongs to other table, so use copy() method to copy the data and structure into another datatable.

DataTable dt = new DataTable();
DataSet dsValue = new DataSet();
dsValue.Tables.Add(dt);
DataSet dsResult = new DataSet();
DataTable dttemp = dsValue.Tables[0].Copy();
dsResult.Tables.Add(dttemp);
  Recent Post
* Log in, Log out... (0) by Jeeva on 15/02/2012
* Unable to start program and showing Element not found error message in Microsoft Visual Studio 2008 (1) by Thamilselvanj on 19/12/2011
* Error : The request channel timed out while waiting for a reply after.. in WCF service. (1) by Thamilselvanj on 08/06/2011
* How to Split the string in sql server? (0) by Spidy on 19/05/2011
* Error : Sys.ArgumentNullException: Value cannot be null Parameter name: element (1) by Thamilselvanj on 19/05/2011