VB.NET - Copy rows between data tables

Publicado el: 10 mayo 2015
en el canal de: KnowledgeIsCool
5,682
7

Here is the code you can use to copy rows from one data table to another.

VB.NET - Copy rows between data tables
-----------------------------------------------
Dim tableOld As New DataTable

'Create 2 columns
tableOld.Columns.Add("ProductID", GetType(Integer))
tableOld.Columns.Add("ProductName", GetType(String))

'Add 2 rows
tableOld.Rows.Add(111, "Apple")
tableOld.Rows.Add(112, "Orange")

Dim tableNew As New DataTable

'Copy table structure of tableOld to tableNew
tableNew = tableOld.Clone()

Dim rowNumber As Integer = 1 'Change the row number as needed
tableNew.ImportRow(tableOld.Rows(rowNumber)) 'Copies a certain row of tableOld into tableNew

'You can only copy an exact row into another table using this approach if both of them have the same table structure.
'That is why we used the Clone() method to copy the table structure.

MessageBox.Show(tableNew.Rows(0).Item("ProductID") & ": " & tableNew.Rows(0).Item("ProductName"))


En esta página del sitio puede ver el video en línea VB.NET - Copy rows between data tables de Duración hora minuto segunda en buena calidad , que subió el usuario KnowledgeIsCool 10 mayo 2015, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 5,682 veces y le gustó 7 a los espectadores. Disfruta viendo!