I have a excel with 10000 records, My requirement is to do following using LINQ. Please help me in this. Suggest only faster way (LINQ), for each data row will be very slow.
Data Table
Header1|Header2|Header3
AAAAAA|0123456|aaaaaaa
BBBBBB|1234567|bbbbbb
CCCCC|2345678|ccccccc
Q1 : I want to add a column name Header4 with value AAAAAA0123456 , BBBBBB1234567 etc. I want to achieve using LINQ.
Q2: I want convert Header2 values to Number (while reading from excel it is in String format). I want to achieve using LINQ.
Yes, this will work. I just want to make it bit dynamic. Now we have only three column, so it is easy to add one more column using Add method. But I have datatable with 96 Columns, where it is difficult to add every column name as part of the code. So is there any other ways to achieve it?
This is market place activity (Balareva), which I am aware. Is there a way using linq it self we can achieve it.
there are several techniques for shortening the explicit column refeencing e.g. by using the entire itemarray or parts from it (e.g. take, skip). But for this we do need the details from the datacolumn structures like 1-96 is to use, 97 is concat of Y,X…
ususally we can do like following:
clone the datatable: dtData2 = dtDataClone
add a datacolumn with corresponding datatype, colname: Header2_1
run following LINQ
dtData2 =
(From d in dtData.AsEnumerable
let cc = Convert.ToDouble(d(Header2))
let ra = d.ItemArray.Append(cc).toArray
Select dtData2.Rows.Add(ra)).CopyToDataTable
move the Column Header2_1 with an invoke method activity: