数据表已属于另一个数据集 [英] DataTable already belongs to another DataSet

查看:120
本文介绍了数据表已属于另一个数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误,同时添加一个数据表,从一个数据集到另一个存在的 数据表已属于另一个数据集。

  dsformulaValues​​.Tables.Add(m_DataAccess.GetFormulaValues
(dv.ToTable.DefaultView.ToTable(假,strSelectedCols))。表(0))
 

解决方案

像其他答复指出,你所看到的错误是因为你正在试图添加到DataSet中的数据表已经是一个不同的一部分数据集。

一种解决方案是<一个href="http://msdn.microsoft.com/en-us/library/system.data.datatable.copy%28VS.90%29.aspx#Y0">Copy数据表和分配复制到其他数据集。

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

复制的数据表将具有以下结构和所复制的数据表的数据

如果您只想DataTable的结构,叫<一href="http://msdn.microsoft.com/en-us/library/system.data.datatable.clone%28v=VS.90%29.aspx">Clone代替。

  dtCopy = dataTable.Clone()
 

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))

解决方案

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()

这篇关于数据表已属于另一个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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