DataTable already belongs to another DataSet

后端 未结 10 1188
滥情空心
滥情空心 2020-12-24 11:14

This error is occuring while adding one datatable from a dataset to another .\"DataTable already belongs to another DataSet.\"

dsformulaValues.Tables.Add(m_D         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 11:33

    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.

    dtCopy = dataTable.Copy()
    ds.Tables.Add(dtCopy)
    

    The copied DataTable will have the structure and data of the copied DataTable.

    If you only want the structure of the DataTable, call Clone instead.

    dtCopy = dataTable.Clone()
    

提交回复
热议问题