Converting DataView to Table





5.00/5 (3 votes)
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