如何在C Sharp中将datatable列从一个表复制到另一个表...
问题描述:
我想将一个数据表的动态选择的列复制到另一数据表.
I want to copy dynamically selected columns of one data-table to another data table.
答
.NET框架中的DataTable类将为您提供帮助.这是将PresentAddress表的列复制到PermanantAddress表的示例.
DataTable class in .NET framework will help you. Herez an example to copy the columns of PresentAddress table to PermanantAddress table.
DataTable PresentAddress = new DataTable();
DataTable PermanantAdress = new DataTable();
foreach (DataRow sourcerow in PresentAddress .Rows)
{
DataRow destRow = PermanantAdress.NewRow();
destRow["Name"] = sourcerow["Nam"];
destRow["Address"] = sourcerow["Addr"];
PermanantAdress.Rows.Add(destRow);
}