I had the same problem and I solved it using Remove
. In my opinion, your code could be this:
dsformulaValues.Tables.Add(m_DataAccess.GetFormulaValues
(dv.ToTable.DefaultView.ToTable(False, strSelectedCols)).Tables(0))
dsformulaValues.Tables.Remove(//I'm not sure to understand your code, so read this code line as only an input for your stuff. Please, consider my code below for more understanding.
My working code was like this:
DataTable myTable = new DataTable();
private void Save()
{
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add(myTable);
myDataSet.Tables.Remove(myTable);//This works
myDataSet.WriteXml("myTable.xml");
}
private void buttonSave_Click(object sender, EventArgs e)
{
Save();
}
Every time I clicked the button buttonSave
, the message “DataTable already belongs to another DataSet" appeared. After writing the line code myDataSet.Tables.Remove(myTable);//This works
the application started running without problems and now I can click the button more times, without losing the value of myTable
and without the error message.
I hope this can help.