且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将一个数据表的列添加到另一个

更新时间:2022-12-09 15:19:56

如果第二个表已经有所有的行,但只有一列缺少
它应该是足够的做这样的事情

if the second table already has all rows, but just one column is missing it should be enough to do something like this

DataTable tbl1;
DataTable tbl2;

tbl1.Columns.Add("newCol");

for(int i=0; i<tbl.Rows.Count;i++)
{
   tbl1.Rows[i]["newcol"] = tbl2.Rows[i]["newCol"];
   tbl1.Rows[i]["date"] = tbl2.Rows[i]["date"];
}