There are multiple ways to copy data from 1 datatable to another.
a)dtnew=dtold.copy();
copies both structure and data
b)dtnew=dtold,clone()
copies only structure.
(we can use it instead of adding columns)
c)
to copies data of specific columns
a)dtnew=dtold.copy();
copies both structure and data
b)dtnew=dtold,clone()
copies only structure.
(we can use it instead of adding columns)
c)
to copies data of specific columns
DataTable dtnew=new DataTable();
dtnew.Columns.Add("sl_no");
dtnew.Columns.Add("Tenant");
foreach(DataRow dr in dt.Rows)
{
DataRow drNew = dtnew.NewRow();
drNew["sl_no"]=dr["slno"];
drNew["Tenant"] = dr["tenant_name"];
dtnew.Rows.Add(drNew);
}
No comments:
Post a Comment