Got this error when trying to create a web service last night:
DataTable already belongs to another DataSet.
My code looked like:
DataSet ds = new DataSet();
DataTable dt = new DataTable("LatestPosts");
dt = dal.GetLatest(5);
ds.Tables.Add(dt);
return ds;
I could see no place where the Datatable was part of another dataset. So I used the Copy method on the datatable and everything worked out fine. Took awhile to locate though (Clone didn't work).
Correct code:
DataSet ds = new DataSet();
DataTable dt = new DataTable("LatestPosts");
dt = dal.GetLatest(5);
ds.Tables.Add(dt
.Copy());
return ds;