从一个数据表添加行到另一个数据表 [英] adding rows from one datatable to another

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

问题描述



以下代码:

For each r As DataRow in dtFlow.Rows

Dim arow As DataRow = dtAllFlows.NewRow

arow = r

dtAllFlows.Rows.Add(arow)

下一页


导致错误''这一行已经属于另一个表''

在行dtAllFlows.Rows.Add(arow)。

我想我应该做dtAllFlows = dtFlow .copy,但我不能将上面的

代码包含在For循环中,并且在每次迭代时,我添加新的

行(每次迭代时dtFlow更改) )。


如何解决这个问题?


问候

Hi,
The following code :
For Each r As DataRow In dtFlow.Rows
Dim arow As DataRow = dtAllFlows.NewRow
arow = r
dtAllFlows.Rows.Add(arow)
Next

leads to the error ''This row already belongs to another table ''
at the line dtAllFlows.Rows.Add(arow).
I guess I should just do dtAllFlows = dtFlow.copy, but I can''t as the
code above is contained in a For loop and at each iteration, I add new
rows (dtFlow changes at each iteration).

How can I solve this problem ?

Regards

推荐答案

Sam,


我认为这就是你想要做的事情


importrow
http ://msdn.microsoft.co m / library / de ... rtrowtopic.asp

我希望这会有所帮助,


Cor
Sam,

I assume that this is what you want to do

importrow
http://msdn.microsoft.com/library/de...rtrowtopic.asp

I hope this helps,

Cor


谢谢Cor ;-)
Thanks Cor ;-)


其实我说得太快了。

For each r As DataRow in dtFlow.Rows

Dim arow As DataRow = dtAllFlows.NewRow

arow = r

dtAllFlows .ImportRow(arow)

下一页


看起来不对,但实际上当我尝试访问数据时:


dtallflows.Rows(0).Item(0)

给出:


抛出运行时异常:System.IndexOutOfRangeException - 不能

找到第0列。


发生了什么事?

Actually, I might have spoken too quickly.

For Each r As DataRow In dtFlow.Rows
Dim arow As DataRow = dtAllFlows.NewRow
arow = r
dtAllFlows.ImportRow(arow)
Next

It looked right but in fact when I try to access the data:

dtallflows.Rows(0).Item(0)

gives :

Run-time exception thrown : System.IndexOutOfRangeException - Cannot
find column 0.

What''s going on ?


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

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