65.9K
CodeProject is changing. Read more.
Home

Converting DataView to Table

starIconstarIconstarIconstarIconstarIcon

5.00/5 (3 votes)

Dec 23, 2010

CPOL
viewsIcon

34315

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:
//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