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: 11450    |  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

Latest Posts