Vb.net 循环以添加来自不同数据表的数据

Vb.net 循环以添加来自不同数据表的数据,vb.net,datatable,Vb.net,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

我要调用到第二个表的数据表:

第一张表:

 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添加到表2的第一行**

   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()
使用表2,如何链接星期一的信息,在表2中添加一个,我需要一个循环来调用它

在第一个表中,我希望周一的1在第二个表中的“一”中显示,即表2

对于alex:

 Monday    Tuesday    Wed
 10           40       9
 20           50       6
 30           70       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
要将值添加到表2中的两列中,请执行以下操作:

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

下面是如何将
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
要将值添加到表2中的两列中,请执行以下操作:

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

在第一个表中,我想在第二个表中的“一”中显示星期一的1。对不起,你的问题不够清楚。你想用表2做什么?在表1中添加表2后,您是否有一个具体的示例来说明您想要得到什么?是的,这在表1中的“星期一”下。要添加到表2中的第1列中。我想将表中的第周一列中的1添加到表2中的第1列中。我认为需要一些循环才能从表中获取。这并没有在第一个表中添加星期一下的1,我希望在第二个表中的“1”中显示星期一下的1,表2..对不起,您的问题不够清楚。你想用表2做什么?在表1中添加表2后,您是否有一个具体的示例来说明您想要得到什么?是的,这在表1中的“星期一”下。要添加到表2中的第1列中。我想将表中的第周一列中的1添加到表2中的第1列中。我认为需要一些循环才能从表中获取它。这不会添加Monday下的1。您可以将索引从0更改为1。。。到4如果“苹果”在表1的第一列,你仍然会做
table2.Rows.Add(row(0))
ooh,所以如果苹果在该列中排名第二,它就会是。table2.Rows.Add(row(2))如果“apple”在table1的第二列,那么它将是table2.Rows.Add(row(1))。。。索引是从零开始的。要从表1到表2中的“星期二”列中获取2005的值,可以执行
table2.Rows.Add(row(1))
。请记住,
行(索引)
的所有内容都来自foreach示例。您可以将索引从0更改为1。。。到4如果“苹果”在表1的第一列,你仍然会做
table2.Rows.Add(row(0))
ooh,所以如果苹果在该列中排名第二,它就会是。table2.Rows.Add(row(2))如果“apple”在table1的第二列,那么它将是table2.Rows.Add(row(1))。。。索引是从零开始的。要从表1到表2中的“星期二”列中获取2005的值,可以执行
table2.Rows.Add(row(1))
。请记住
行(索引)
中的所有内容都来自foreach示例。