如何在 C# / ADO.NET 2.0 中获取使用 DataTable.NewRow() 创建的行?
现在我使用 Select 并使用仅选择新行的条件。但是有没有任何类型的 GetInsertedRows 方法。如果我没记错的话,每一行都有状态,因此自然可以循环遍历所有行,但这并不优雅。
-干杯-马蒂
Now I use Select and use a criteria which select only new rows. But is there any kind of GetInsertedRows-method. If I remember correctly there is status for each row so naturally one can loop through them all but that's not elegant.
-Cheers -Matti
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢 TypeT 的答案,但知道您始终通过 DataView 绑定到 DataTable 并且可以将其设置为过滤行状态可能会有所帮助:
您还可以创建一个额外的 DataView 来查看新的或删除的行,然后这些视图不会互相字节:
I like TypeT's answer but it may help to know that you always bind through a DataView to a DataTable and you can set it to filter on the rows state:
You can also create an additional DataView to look at the new or deleted rows, and then those Views won't byte each other:
我自己不久前也遇到过这个问题,但是没有很好的方法来提取添加的行。我刚刚为您搜索了我的存储库,找到了我曾经使用的
DataTable
实现:它仍在进行迭代,但它很好地包装为
IEnumerable
,您将不会'不必多次编写代码。I came across this issue myself a while ago, however there's no nice way of pulling out the added rows. I've just trawled my repositories for you and found the
DataTable
implementation I used to use:It's still doing an iteration, but it's nicely wrapped as an
IEnumerable
and you won't have to write the code more than once.