I need to append a row from databla1 to datatable2 that has already rows, I tried to importrow(), clone(), but I cant' find the solution:
The datatable1 has this structure:
name | surname | iddepartment | address | phone1 | phone2 | country | cp | birthdate |
datatable2是在类中创建的公共数据表:
Public Shared datable2 As New DataTable
我有这段代码:
Dim datatable1 As DataTable = getdata("myQuery")
我试图这样做,但是我收到了一个错误:
Dim newRow= datatable1.Rows(0)
myClass.datatable2.rows.add(newRow)
我该怎么做?感谢
答案 0 :(得分:0)
据我了解。
VB.NET示例:
'db query result'
table.Columns.Add("Name", GetType(String))
table.Columns.Add("surname", GetType(String))
table.Columns.Add("iddepartment", GetType(Integer))
table.Columns.Add("phone1", GetType(String))
table.Columns.Add("phone2", GetType(String))
table.Columns.Add("country", GetType(String))
table.Columns.Add("cp", GetType(String))
table.Columns.Add("birthdate", GetType(DateTime))
'column set'
Dim table2 As DataTable = table
Dim i As Integer = 0
'add dummy data'
For index = 1 To 10
'instance new dataRow '
Dim dr As DataRow = table2.NewRow
dr("Name") = "Jack"
dr("surname") = "Daniels"
dr("iddepartment") = i
dr("phone1") = "099999"
dr("phone2") = "09999"
dr("country") = "USA"
dr("cp") = "-"
dr("birthdate") = New DateTime
table2.Rows.Add(dr)
i = i + 1
Next
'each table2 rows'
For Each rowItem As DataRow In table2.Rows
Console.WriteLine(rowItem("Name"))
Console.WriteLine(rowItem("surname"))
Console.WriteLine(rowItem("iddepartment"))
Console.WriteLine(rowItem("phone1"))
Console.WriteLine(rowItem("phone2"))
Console.WriteLine(rowItem("country"))
Console.WriteLine(rowItem("cp"))
Console.WriteLine(rowItem("birthdate"))
Next
Console.Read()