DataView vs. DataTable
using System;
using System.Collections;
using System.Data;
public class MyTestClass
{
public static void Main()
{
DataTable dt = new DataTable();
try
{
DataColumn col1 = new DataColumn();
col1.DataType = System.Type.GetType("System.Int32");
col1.ColumnName = "EmployeeID";
dt.Columns.Add(col1);
DataColumn col2 = new DataColumn();
col2.DataType = System.Type.GetType("System.String");
col2.ColumnName = "LastName";
dt.Columns.Add(col2);
dt.Rows.Add(new Object[] {1, "Covell"});
dt.Rows.Add(new Object[] {2, "Schaefer"});
dt.Rows.Add(new Object[] {3, "Krause"});
dt.Rows.Add(new Object[] {4, "Meloskie"});
dt.Rows.Add(new Object[] {5, "Vader"});
MyDataView myView = new MyDataView(dt, "EmployeeID < 3");
Console.WriteLine("Filter row count: {0}", myView.CurrentFilterCount);
Console.WriteLine("Row count: {0}", myView.CurrentCount);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
Console.WriteLine("Done and done.");
Console.ReadLine();
}
}
}
public class MyDataView : DataView
{
public MyDataView(DataTable dt, string filter) : base(dt)
{
this.RowFilter = filter;
}
public int CurrentFilterCount
{
get { return this.Count; }
}
public int CurrentCount
{
get { return this.Table.Rows.Count; }
}
}
Labels: .net

0 Comments:
Post a Comment
<< Home