Build a datatable with same format and data → name as dtData
dtResults = dtData.Clone
dtResults = (From dte In dtTable.AsEnumerable
Group dte By col1=dte(2).ToString.Trim Into Group
Select dtResults.Rows.Add({col1, Group.Sum(Function (x) CInt(x(1).toString.Trim))})).CopyToDataTable
@Sugumar8785
my linq would look same like this one from GBK. Is it running?
Dont miss out to modify dtResult after cloning and do remove the unneeded columns Col1,Col4. Another option wouldbe to use buld datatable and modelling the structure as needed by dtResult. For getting it clean, use a clear datatable afterwards as often an empty row will be present
@GBK I have extended your query for other columns as below. But If any columns are having empty values, it is throwing exception. How can I prevent this issue?
dtResults = (From dte In dtTable.AsEnumerable
Group dte By col1=dte(2).ToString.Trim Into Group
Select dtResults.Rows.Add({col1, Group.Sum(Function (x) CInt(x(1).toString.Trim)), Group.Sum(Function (x) CInt(x(2).toString.Trim)) , Group.Sum(Function (x) CInt(x(3).toString.Trim))})).CopyToDataTable
Exception: Conversion from string “” to type ‘Double’ is not valid.