badal kumar
badal kumar

Reputation: 3

How to concatenate multiple column values into one column in datatable c#

I have a datatable with 3 columns( col1,col2,col3) I have added an extra column with col4(Lets say).

Now My requirement is :

Col1 ||    col2 ||  col3  ||  col4

A          B        C         Col1-A;Col2-B;Col3-C 

Basically, I want a concatenated values in the new column of the existing column name and values as demonstrated above. Hope my requirement is understood. Thanks in Advance!

Upvotes: 1

Views: 3463

Answers (1)

Mohit S
Mohit S

Reputation: 14064

This might do the trick for you

DataColumn newColumn;
newColumn = new DataColumn("col4");
newColumn.Expression =  string.Format("Col1\-{0};Col2\-{1};Col3\-{2}", col1, col2, col3);
scaleResponseData.Columns.Add(newColumn);

Upvotes: 2

Related Questions