C# Convert DataView to Table (DataTable) in .NET 1.1

3.5k views Asked by At

I have a dataview on which I have set a rowfilter:

DataView dv = ds.Tables[0].DefaultView;

dv.RowFilter = "here my filter";

Once data filtered, I want to convert it to a DataTable. I know this is possible in .NET 2.0 and above, using it:

Datatable result  = dv.ToTable();

But how to do this in .NET 1.1?

2

There are 2 answers

0
Azar Shaikh On

How about this a workaround using Datatable Select

DataTable dt = ds.Tables[0];
DataTable filterdt = dt.Clone(); //Available from .Net 1.1

//Datatable Select Available from .Net 1.1              
DataRow[] filterRows = dt.Select("here you filter"); 



 //Loop filterRows[] and import to filterdt Datatable

  foreach (DataRow filterRow in filterRows)
                filterdt.ImportRow(filterRow); //Datatable Import row Available from .Net 1.1
0
Tim Schmelter On

This works in .NET 1.1 because the enumerator of the DataView only returns the filtered rows:

DataTable table = dv.Table.Clone();
foreach (DataRowView rowView in dv)
    table.ImportRow(rowView.Row);