从DataTable中删除行 [英] Deleting a Row from a DataTable

查看:407
本文介绍了从DataTable中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个dataTable说dt1,现在我想从这个数据表中删除一行,我用dr.delete()和dt.AcceptChanges()方法做同样的事情但是我收到了错误。

我收到了这个错误:=

收藏被修改了;枚举操作可能无法执行。


你能告诉我这个解决方案。



谢谢

Rohit Vyas

Hello all,
I have a dataTable say dt1,now i want delete a row from this datatable,i have used dr.delete() and dt.AcceptChanges() methode to do the same but i got error .
I got this error:=
Collection was modified; enumeration operation might not execute.

Can you people tell me the solution of this.


Thanks
Rohit Vyas

推荐答案


大家好,

我有一个dataTable说dt1,现在我想从这个数据表中删除一行,我使用dr.delete()和dt.AcceptChanges()方法做同样的但我得到了错误。

我收到此错误:=

收藏品已被修改;枚举操作可能无法执行。


你能告诉我这个解决方案。



谢谢

Rohit Vyas
Hello all,
I have a dataTable say dt1,now i want delete a row from this datatable,i have used dr.delete() and dt.AcceptChanges() methode to do the same but i got error .
I got this error:=
Collection was modified; enumeration operation might not execute.

Can you people tell me the solution of this.


Thanks
Rohit Vyas



这是因为你在迭代它时无法修改实际的集合。如果列表大小很小,请使用ToArray方法并对其进行迭代,否则创建需要删除的所有值的另一个列表,然后在第一次迭代后在单独的循环中执行删除。

That''s because you cannot modify the actual collection while you''re iterating through it. If the list size is small, use the ToArray method and iterate over that, otherwise create another list of all the values that need to be deleted and then do the deletion in a separate loop after the first iteration.



那是因为你在迭代它时不能修改实际的集合。如果列表大小很小,请使用ToArray方法并对其进行迭代,否则创建需要删除的所有值的另一个列表,然后在第一次迭代后在单独的循环中执行删除。
That''s because you cannot modify the actual collection while you''re iterating through it. If the list size is small, use the ToArray method and iterate over that, otherwise create another list of all the values that need to be deleted and then do the deletion in a separate loop after the first iteration.



感谢您的回复

您能告诉我代码吗,我该怎么办...

Thanks for reply
Can you show me the code,how can i do it...



感谢您的回复

您能告诉我代码,我该怎么做...
Thanks for reply
Can you show me the code,how can i do it...



代码基本上取决于您使用什么标准进行删除。


我不喜欢编写代码并热衷于讨厌.NET但是如果按下我会说你需要做一些像

The code basically depends on what criteria you''re using for deleting.

I don''t like writing code and hate .NET passionately but if pressed I''d say you need to do something like

展开 | 选择 | Wrap | 行号


这篇关于从DataTable中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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