I am using below query to get serial number based on my column1. I want the serial number to be in 5 digits format. (00001 to 99999). But the String.Format isnt working inside the linq query. I am not sure how to get this done. Please help me on this. The below LINQ Query works without string.Format and creates serial number.
(From d In dtData.AsEnumerable
Group d By k=d(0).toString.Trim Into grp=Group
Select grp.Select(Function (r, i) dtResult.Rows.Add({r(0), (i+1)})).ToList).SelectMany(Function (x) x).CopyToDataTable
Doesnt work:
(From d In dtData.AsEnumerable
Group d By k=d(0).toString.Trim Into grp=Group
Select grp.Select(Function (r, i) dtResult.Rows.Add({r(0), String.Format(“0:D5”,(i+1))})).ToList).SelectMany(Function (x) x).CopyToDataTable
Desired Output:
ColumnA ColumnB
A_1_X - 00001
A_1_X - 00002
A_1_X - 00003
A_1_Y - 00001
A_1_Y - 00002
A_2_X - 00001
A_2_X - 00002
A_2_Y - 00001
B_1_X - 00001
B_1_X - 00002
B_1_Y - 00001