使用Linq获得不同的行



我正在使用linq对数据进行分组,您可以从下面的代码中看到,在分组之后,我想对组数据进行交互并添加到另一个表中。

但是我只得到InvoiceHeader。关键,我不知道如何获得其他字段

        DataTable VendorInvoiceStagingTable;
        DataTable VendorInvoiceTable;
        VendorInvoiceStagingTable = new Program().ReadExcelFile(@"C:Usershuzaifa.gainDesktopVendor invoice import - sample data set.xlsx", "Sheet2");
        var InvoiceHeadercollection = from row in VendorInvoiceStagingTable.AsEnumerable()
                            group row by row.Field<string>(VendInvoice.Number) into grp
                            select grp;


         VendorInvoiceTable =  new Program().CreateHeader();
         foreach (var InvoiceHeader in InvoiceHeadercollection)
        {
         VendorInvoiceTable.Rows.Add(InvoiceHeader.Key, .....

        }

由于InvoiceHeader是实现IEnumerableIGrouping,您可以简单地枚举组中的项目,因此您可以使用foreach循环:

foreach (var InvoiceHeader in InvoiceHeadercollection)
{
  foreach(var row in InvoiceHeader)
      VendorInvoiceTable.Rows.Add(row);
}

相关内容

  • 没有找到相关文章

最新更新