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
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
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
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:
Regards,