Search code examples
vb.netdatatabledatacolumn

How to merge two column which are already exist in one datatable?


I have one datatable. In that table I have columns named [Total Day], [Present day], and [leave]. Data are as follows:

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

Now i want to concatenate those three columns in one another column. I want output something like this:

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

Solution

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

    Assuming that the square brackets are not part of the column name, if they are, use "[[Total Day\]]" etc. For details, see: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx