Copy DataTable to Another DataTable with Specific Columns using c#.net
Previously in THIS post, showed how to ADD, UPDATE, DELETE in a DataTable using C#.
Now i will show how to copy data from one table to another table for specific columns only as for the requirement at some situations.
Code :
protected void btnCopy_Click(object sender, EventArgs e)
{
try
{
DataTable newTable = dt.DefaultView.ToTable(false, "Name", "Sal");
GridView2.DataSource = newTable;
GridView2.DataBind();
}
catch (Exception ex)
{
string ErrMsg = ex.Message;
}
}
Here dt is source datatable.
Click Here to Download
Now i will show how to copy data from one table to another table for specific columns only as for the requirement at some situations.
Code :
protected void btnCopy_Click(object sender, EventArgs e)
{
try
{
DataTable newTable = dt.DefaultView.ToTable(false, "Name", "Sal");
GridView2.DataSource = newTable;
GridView2.DataBind();
}
catch (Exception ex)
{
string ErrMsg = ex.Message;
}
}
Here dt is source datatable.
Click Here to Download
No comments:
Post a Comment