DataTable已经属于另一个DataSet [英] DataTable already belongs to another DataSet

查看:1580
本文介绍了DataTable已经属于另一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆