开发者

Getting distinct rows usin Linq

I am grouping Data using linq as you can see from the following code, after group i want to interate over the group data and add to another table.

But I am only getting InvoiceHeader.Key, I dont know how to get other fields

        DataTable VendorInvoiceStagingTable;
        DataTable VendorInvoiceTable;
        VendorInvoiceStagingTable = new Program().ReadExcelFile(@"C:\Users\huzaifa.gain\Desktop\Vendor 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.R开发者_如何转开发ows.Add(InvoiceHeader.Key, .....


        }


Since InvoiceHeader is an IGrouping which implements IEnumerable you can simply enumerate the items in the group, so you can just use a foreach loop:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜