3

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?

Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    Out of curiosity Still, use .net 1.1.. – too_cool May 30 '17 at 10:10
  • Don't you already have a datatable : ds.Tables[0]. A dataset consists of datatables. – jdweng May 30 '17 at 10:10
  • 1
    The source code of the framework is available. At first sight it doesn't seem to be impossible create a ToTable method yourself http://referencesource.microsoft.com/System.Data/a.html#8d3e2c3c04b09ed6 – Steve May 30 '17 at 10:12
  • @too_cool Yes, it is a legacy project and it will be migrated soon in future. But now I need to do this modification. – Willy May 30 '17 at 10:15
  • Should have given a try but don't have VistualStudio to support that. :( – too_cool May 30 '17 at 10:20
  • 1
    [Chk this out](http://www.codedigest.com/CodeDigest/54-Copy-the-Sorted-Filtered-Dataview-To-DataTable-in--Net-1-1.aspx) Might help – too_cool May 30 '17 at 10:21
  • @Steve i get error on line List rowlist = new List(); when trying to adapt it. Net 1.1 does not recognize it. – Willy May 30 '17 at 10:24
  • @too_cool I'll try it. thx. – Willy May 30 '17 at 10:38

2 Answers2

0

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
Azar Shaikh
  • 445
  • 9
  • 26
0

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);
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939