Datafrom DT's

i have two different datatables and i need data from both the DB’s into a DT Final_DT, but the result i am able to see is only UTIL value and HOSTVAL, READ,WRITE is missing, what should i correct

image

Looks like yo are overwriting the previous results (Final_DT)

Can you share the

  • input data
  • expected output data

So we can verify our guess, that you are looking for a side-by-side merge

Hi @ppr

Input1.xlsx (8.2 KB)
Input2.xlsx (8.3 KB)
Final_Output.xlsx (8.3 KB)

PFA

Its a side-by-side merge

Done on exel directly

  • write dt2 to Worksheet of dt1 with a range offset of B1

OR

done on datatable base

UPD1 - above is just about mentioning a few options out of many options we do have

Hi @devasaiprasad_K

Try this

Code:

DTResult = New DataTable()

' Add columns from DT1 to DTResult
For Each col As DataColumn In DT1.Columns
    DTResult.Columns.Add(col.ColumnName, col.DataType)
Next

' Add columns from DT2 to DTResult
For Each col As DataColumn In DT2.Columns
    DTResult.Columns.Add(col.ColumnName, col.DataType)
Next

' Merge the rows
For i As Integer = 0 To DT1.Rows.Count - 1
    Dim newRow As DataRow = DTResult.NewRow()
    ' Copy data from DT1
    For Each col As DataColumn In DT1.Columns
        newRow(col.ColumnName) = DT1.Rows(i)(col)
    Next
    ' Copy data from DT2
    For Each col As DataColumn In DT2.Columns
        newRow(col.ColumnName) = DT2.Rows(i)(col)
    Next
    ' Add the new row to the result DataTable
    DTResult.Rows.Add(newRow)
Next

Output:

image

Regards,

@devasaiprasad_K

FYI, There is another approach

Output:

image

Regards,