DataTable已经属于另一个DataSet [英] DataTable already belongs to another DataSet
问题描述
在数据集添加到另一个
时,会发生此错误。DataTable已经属于另一个DataSet。
This error is occuring while adding one datatable from a dataset to another ."DataTable already belongs to another DataSet."
dsformulaValues.Tables.Add(m_DataAccess.GetFormulaValues
(dv.ToTable.DefaultView.ToTable(False, strSelectedCols)).Tables(0))
推荐答案
像其他回应指出,您所看到的错误是因为您尝试添加到的DataTable DataSet已经是不同DataSet的一部分。
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.
一个解决方案是复制 DataTable并将副本分配给其他DataSet。
One solution is to Copy the DataTable and assign the copy to the other DataSet.
dtCopy = dataTable.Copy()
ds.Tables.Add(dtCopy)
复制的DataTable将具有复制的DataTable的结构和数据。
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()
这篇关于DataTable已经属于另一个DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!