VB.NET - Copy rows between data tables

Pubblicato il: 10 maggio 2015
sul canale di: 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"))


In questa pagina del sito puoi guardare il video online VB.NET - Copy rows between data tables della durata di ore minuti seconda in buona qualità , che l'utente ha caricato KnowledgeIsCool 10 maggio 2015, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 5,682 volte e gli è piaciuto 7 spettatori. Buona visione!