VB.NET - Copy rows between data tables

Veröffentlicht am: 10 Mai 2015
auf dem Kanal: 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"))


Auf dieser Seite können Sie das Online-Video VB.NET - Copy rows between data tables mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer KnowledgeIsCool 10 Mai 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 5,682 Mal angesehen und es wurde von 7 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!