我想在第二张桌子上打电话给我的DataTable:
第一张表:
Dim table As New DataTable
' columns in the DataTable.
table.Columns.Add("Monday", System.Type.GetType("System.Int32"))
table.Columns.Add("Tuesday", System.Type.GetType("System.Int32"))
table.Columns.Add("Wednesday", System.Type.GetType("System.Int32"))
table.Columns.Add("Thursday", System.Type.GetType("System.Int32"))
table.Columns.Add("Friday", System.Type.GetType("System.Int32"))
' rows with those columns filled in the DataTable.
table.Rows.Add(1, 2005, 2000, 4000, 34)
table.Rows.Add(2, 3024, 2343, 2342, 12)
table.Rows.Add(3, 2320, 9890, 1278, 2)
现在这是我需要循环的第二个表:
**未完成,想在第一行中从表格添加1到表格。**
Dim table2 As New DataTable
' columns in the DataTable.
table2.Columns.Add("one", System.Type.GetType("System.String"))
table2.Columns.Add("two", System.Type.GetType("System.String"))
table2.Rows.Add() *** add 1 (from monday) from first table**** ??
table2.Rows.Add()
table2.Rows.Add()
table2.Rows.Add()
使用table2,如何链接星期一的信息,在表2中添加一个,我需要一个循环,我想调用它。
在第一个表格中,我想要在星期一的1中显示在第二个表table2中的“one”。
对于亚历克斯:
Monday Tuesday Wed
10 40 9
20 50 6
30 70 4
答案 0 :(得分:4)
以下是如何<{>将Table1
的第一列值添加到Table2
For Each row As DataRow In table.Rows
table2.Rows.Add(row(0)) 'This will add the first column value of Table1 to the first column of Table2
'Here's how the index works:
'table.Rows.Add(1, 2005, 2000, 4000, 34)
'row(0) = 1
'row(1) = 2005
'row(2) = 2000
'row(3) = 4000
'row(4) = 34
Next
要在Table2中为两列添加值,您可以这样做:
For Each row As DataRow In table.Rows
table2.Rows.Add({row(0), row(1)})
'If I take your second example:
Monday Tuesday Wed
10 40 9
20 50 6
30 70 4
'The first iteration through Table1 will add (10,40)
'The second iteration through Table1 will add (20,50)
'And so on...
Next