How to convert data table rows to string using LINQ queries?

Hi All,

Can someone help me in converting data table rows to string using LINQ queries ?

Actual Dt name : dt_FilteredTableData (I have read this from excel)

Created similar DT : dt_Leadzeros (Like below)

I tried below query but didn’t work

dt_FilteredTableData = (from row in dt_FilteredTableData Let x=New Object(){row(“G/L Account”).ToString,row(“Company Code”).ToString,row(“Post automatically only”).ToString,row(“Only balances in local crcy”).ToString,row(“Relevant to cash flow”).ToString,row(“Blocked for posting”).ToString} select dt_Leadzeros.Rows.Add(x)).copytoDatatable

Naresh @J0ska

Hi @Mandava_Naresh

Can you share the excel file?

What is the issue you are facing with the above LINQ

@kumar.varun2 I have value 0004 in excel while reading and leading zeros is getting missed and only 4 is getting updated in excel after using excel write range… So I want to convert using LINQ

Alter below mock up to meet your case

dt2 = (From row In dt1.AsEnumerable
Select dt2.Rows.Add(CStr(row.item(“item1”)),row.item(“item2”))).CopyToDataTable


Hi J0ska,

Tried as you suggested but still I am l getting the error.

error screenshot

LINK screenshot


Hi @Mandava_Naresh, I hope you are doing well.
For your problem statement I am attaching a sample workflow which might help you with your solution.
LinqQuery.xaml (10.6 KB)

Have a good day!

Thanks & Regards,
Shubham Dutta

Thank you for response @Shubham_Dutta … File attached by you is concatenating the data in the last row… I just want to convert all rows to string from dt1 using LINQ query and put in new data table dt2 or use converted dt1 directly in excel write range

This is not a problem of the principle but a problem of your implementation.
Probably some typo in column name.
Validate in debug mode the structure of “dt_FilteredTableData”


Hi @Mandava_Naresh,
The process i sent you is a sample for reference in that I am converting one datatable i.e dt to another datatable i.e dtOutput only.Please see the write range activity.

And if you want to change the datatype and check change the datatype in input datatable i.e dt into int32. Still you will get all string values in dtOutput datatable.

Thanks & Regards,
Shubham Dutta

Column name is correct …I am not sure why it is failing

I can see some red mark in the query but not showing as error


It seems to be the problem. Retype the double quotes.


I need something like below without concatenation in the end

(from row in dt Let x=New Object(){row(“Name”).ToString,row(“Empty”).tostring,row(“Salary”).ToString,row(“Variable”).ToString,row(“Name”).ToString+row(“Empty”).tostring+row(“Salary”).ToString+row(“Variable”).ToString} select dtOutput.Rows.Add(x)).copytoDatatable

I have updated and red mark got removed but still no luck :frowning:


and make sure it contains “G/L Account” column

or use just column indexes in the expression to avoid column name trigered error
dt2 = (From row In dt1.AsEnumerable
Select dt2.Rows.Add(CStr(row.item(0)), row.item(1), row.item(2)…)).CopyToDataTable


1 Like

It worked … Thank you @J0ska

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