如何将数据库表中的数据传递给另一个数据表。 [英] How to pass data in database table to another datatable.
问题描述
需要一些帮助才能将数据表中的数据传递到另一个数据表。
我想在另一个数据表中传递数据。
3 Datatable是
产品1
产品2
产品3
如果产品2没有库存1或3可以将产品传递给产品2而其他产品也相同。
提前谢谢。
Hi, need some help for passing data in datatable to another datatable.
I want to pass data in another datatable.
The 3 Datatable is
Product1
Product2
Product3
if product 2 has no more stock 1 or 3 can pass product to product 2 and same for the others.
Thanks in advance.
推荐答案
您可以通过DataTable.Copy方法 [ ^ ]。
如果你只想复制某些行,你可以编写如下代码。
You can copy the whole table to another table by DataTable.Copy Method[^].
If you want to copy certain rows only, you can code something like below.
foreach (DataRow dr in dataTable1.Rows) {
if (/* some condition */)
dataTable2.Rows.Add(dr.ItemArray);
}
提供 dataTable1
和 dataTable2
具有相同的数量,类型和列的顺序。
如果它们的模式不同,那么在循环内部,您必须获取所需的列值并将其添加到其他表中的相应列。
Provided dataTable1
and dataTable2
have the same number, type and order of columns.
If their schema are different, then inside the loop, you have to get the required column values and add that to respective column in other table.
这篇关于如何将数据库表中的数据传递给另一个数据表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!