简体   繁体   English

在已删除的行上“跳转”

[英]“Jump” over deleted rows

My datatable contains a large number of empty rows that are deleted. 我的数据表包含大量已删除的空行。 I'm using the following code to split the table into several new tables based on the value of Printers , however I need to add contingency for those deleted rows. 我正在使用以下代码根据Printers的值将表拆分为几个新表,但是我需要为已删除的行添加偶然性。 How can I add this contingency within the following statement? 如何在以下语句中添加此意外事件?

List<DataTable> dtCollection = dt.AsEnumerable()
                   .GroupBy(row => row.Field<string>("Printers"))
                   .Select(g => g.CopyToDataTable())
                   .ToList();`

My theory is that I should be able to create some sort of bool within GroupBy , but I'm not sure how to approach this. 我的理论是我应该能够在GroupBy创建某种布尔型,但是我不确定如何实现。

If you want to filter out those rows which were deleted, then you can use simple Where statement which checks state of a row: 如果要过滤掉那些已删除的行,则可以使用简单的Where语句来检查行的状态:

List<DataTable> dtCollection = dt.AsEnumerable()
                   .Where(row => row.RowState != DataRowState.Deleted)
                   .GroupBy(row => row.Field<string>("Printers"))
                   .Select(g => g.CopyToDataTable())
                   .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM