DataTable dt3 = dt1.Clone();
for(inti = 0;i < dt2.Columns.Count;i++)
{
dt3.Columns.Add(dt2.Columns[i].ColumnName);
}
object[] obj = new object[dt2.Columns.Count];
for(inti = 0;i<
{
dt1.Rows[i].ItemArray.CopyTo(obj,0);
dt3.Rows.Add(obj);
}
if (dt1.Rows.Count>=
{
for (inti = 0; i <
{
for (intj = 0; j <
{
dt3.Rows[i][j+
}
}
}
else
{
DataRow dr3;
for (inti = 0; i <
{
dr3 = dt3.NewRow();
dt3.Rows.Add(dr3);
}
for (inti = 0; i <
{
for (intj = 0; j <
{
dt3.Rows[i][j+
}
}
}
本文介绍了一种将两个DataTable对象合并的方法。首先复制第一个表的结构并添加第二个表的列,然后将两个表的数据行合并到新的DataTable中。特别地,如果两表行数不等,会通过填充空行来确保数据的完整性。
1318

被折叠的 条评论
为什么被折叠?



