Create additional rows in Datatbale

Hello,

I’m looking to create new rows in a datatable where there is content in column C.

For example the original datatabe (dt1):

A B C D
123 Ford Red Petrol
456 Kia Blue Diesel
789 Audi Petrol

dt1 should become the following, ordered by column A:

A B C D
123 Ford Red Petrol
123 Ford Petrol
456 Kia Blue Diesel
456 Kia Diesel
789 Audi Petrol

Is this possible using Linq?

case have a risk of getting OverLINQ-ed (when no grouping is done)

Assign Activity:
dtResult = YourDataTable.Clone

EDITED: 1.1 - Quickfix
Assign Activity
dtResult =

(From d In dtData.AsEnumerable
Group d By k= d("A").toString.Trim Into grp=Group
Let hasBlank = grp.Any(Function (x) isNothing(x("C")) OrElse String.IsNullorEmpty(x("C").toString.Trim))
Let raXtra = grp.First().ItemArray.Take(2).Append("").Concat(grp.First().ItemArray.Skip(3)).Cast(Of Object).toArray
Let raSet = grp.Select(Function (x) x.ItemArray)
Let gset = If(hasBlank, raSet, raSet.Append(raXtra))
From ra In gset
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
1 Like

Excellent! Thank you @ppr

quick fix done above

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.