且构网

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

如何在C Sharp中将datatable列从一个表复制到另一个表...

更新时间:2022-12-12 11:21:40

.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);
}