How to prepend a single quote in particular column using Linq query

How to prepend a single quote in particular column using Linq query.
Assume dt is a datatable.
and Columnname=“Id”

@pradnyajadhav0712

you dont need a linq as well…comprehension should do

dt.Columns("ID").Expression = "' + [ID]"

if you need linq only then

invoke code with passing dt as in/out

dt.AsEnumerable.ToList.ForEach(sub(x) x("ID") = "'" + x("ID").ToString)

cheers

is close to updating a column value. Find here an overview on the different approaches
How to Update Data Column Values of a Data Table | Community Blog

using the expression appproach is very powefull and also direct. However, when using the Expression within a self assignment (does mean, manipulate the own column within the setting result) then check at least very carefully for side effects

Thanks a lot @Anil_G! It is working fine

1 Like

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