Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / ADO.NET

Converting DataView to Table

5.00/5 (3 votes)
24 Dec 2010CPOL 34.2K  
Creating a DataTable from a DataView - DataView.ToTable()
In ADO.NET 2.0, the DataView Object has a new method called ToTable, which allows you to create a new table based on data in the DataView.

Here is an example that we used above that creates a new DataTable listing Brazilian Contact Names only:

C#
//Filtered records
DataView dv = new DataView(GetTable(),"Region = 'SP' and Country = 'Brazil'", "ContactName", DataViewRowState.CurrentRows);
//Create new table based on filtered records
DataTable newTable = dv.ToTable("BrazilianContactNames", true, new string[] { "ContactName" });
//Bind grid with only filtered records
dataGridView1.DataSource = newTable.DefaultView;


For more details, please click here[^]

Thanks,
Imdadhusen

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)