2015-11-18 30 views
1

我有一個包含3列(col1,col2,col3)的數據表 我已經添加了一個額外的列col4(可以這麼說)。現在如何將多個列值連接成數據表中的一列c#

我的要求是:

Col1 || col2 || col3 || col4 

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

基本上,我想在現有的列名的新列一個連接值和值如上所示。 希望我的要求被理解。 在此先感謝!

+0

如果你知道如何插入和檢索值基本上可以做一個'的String.Format(「Col1- {0}做的伎倆; Col2- {1}; COL3 -C {2}「,Col1Val,Col2Val,Col3Val);'並將其值插入Col4 –

回答

1

這可能會爲你

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

thnks!修改了一下,它的工作。 –

相關問題