如何合并一个数据表中已存在的两列?

时间:2012-04-05 15:00:02

标签: vb.net datatable datacolumn

我有一个数据表。在该表中,我有名为[Total Day],[Present day]和[leave]的列。 数据如下:

[Total Day], [Present day], [leave]
   30           25             5
   30           26             4

现在我想在另一列中连接这三列。我想输出这样的东西:

[Total Day] [Present Day] [Leave]  [TotalDay    PresentDay  Leave]
30           25             5      30 VBCrLf    25 VBCrLf     5
30           26             4      30 VBCrLf    26 VBCrLf     4

2 个答案:

答案 0 :(得分:1)

table.Columns.Add("TotalDay    PresentDay  Leave", GetType(String), "[Total Day] + '" & vbCrLf & "' + [Present Day] + '" & vbCrLf & "' + [Leave]")

假设方括号不是列名的一部分,如果是,请使用“[[Total Day \]]”等。有关详细信息,请参阅:http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

答案 1 :(得分:0)

SELECT [Total Day], [Present Day], [Leave], 
       [Total Day] + '\n' + [Present Day] + '\n' + [Leave] As [TotalDay PresentDay Leave]
FROM MyTable