从DataTable中删除行

编程入门 行业动态 更新时间:2024-10-22 14:28:03
本文介绍了从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中删除行

本文发布于:2023-10-23 13:56:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521018.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DataTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!