嘿所有人都需要一个帮助为这张表排序循环的帮助,似乎无法将一个工作示例应用于该模型,无论如何它就是这样。将一个数据表的列添加到另一个
我有2个数据表,每个数据表具有不同的数据和不同的值,唯一共同的值是日期。第一个表具有我想要的所有内容,除了一列值(来自另一个表)因此,我需要将此列合并到第一个表上,而不是所有其他数据合并到第一个表中。
所以最好我想的东西,看起来像这样:
DataTable tbl1; //Assume both are populated
DataTable tbl2;
tbl1.Columns.Add("newcolumnofdata") //Add a new column to the first table
foreach (DataRow dr in tbl.Rows["newcolumnofdata"]) //Go through each row of this new column
{
tbl1.Rows.Add(tbl2.Rows["sourceofdata"]); //Add data into each row from tbl2's column.
tbl1.Columns["date"] = tbl2.Columns["date"]; //The date field being the same in both sources
}
如果任何人都可以帮忙WUD欣赏它,就像我说我只需要一列,我不需要有整个其他数据表。干杯。
谢谢你的工作。 – markdigi 2009-08-24 15:41:24