How to convert DataView back to DataTable?

 Posted by vishalneeraj-24503 on 12/8/2013 | Category: ADO.NET Interview questions | Views: 923 | Points: 40

With the help of DataView' ToTable() method we can convert
DataView back to DataTable.

For ex:-

As we know that,DataView is used for sorting and filtering purposes.
Sometimes,we do not have an Order By clause in the query,so we have such functionality with the help of Dataview Sort property.

For Example:-

DataTable dt = new DataTable();

dt.Rows.Add("1", "Vishal");
dt.Rows.Add("2", "Rajesh");
dt.Rows.Add("3", "Prashant");
dt.Rows.Add("4", "Dharmesh");
dt.Rows.Add("5", "Nitin");

DataView dv = dt.DefaultView;
dv.Sort = "Name Desc";

DataTable dt_new = dv.ToTable();

Gridview1.DataSource = dt_new;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response