Monday, July 1, 2013

DataTable already belongs to another DataSet Exception

Exception Occure : DataTable already belongs to another DataSet Exception :-
--------------------------------------------------------------------------------



Like the other responses point out, the error you're seeing is because the DataTable you're attempting to add to a DataSet is already a part of a different DataSet.

One solution is to Copy the DataTable and assign the copy to the other DataSet.

dataTable dtCopy = datatable1.Copy();
ds.Tables.Add(dtCopy);
Your problem will solve.

1 comment: