Using DataViews

Using DataView s

A DataView is an object that allows you to create multiple views of your data and that can be used for data binding. The concept is fairly simple, but its importance cannot be overstated. The flexibility it introduces is impressive because a DataView does not actually change the DataTable from which it is generated. Instead, it offers a filtered window to the data. The following code shows how you can use the DataView control to filter rows based on a column value (in this case, the FirstName and LastName columns):

Function DataViewTest()    Dim adapter As New OleDbDataAdapter("Select * From Customers", _    connStr)    Dim ds As New DataSet()    adapter.Fill(ds)    Dim view1 As DataView = ds.Tables("Customers").DefaultView    Dim view2 As DataView = ds.Tables("Customers").DefaultView    view1.RowFilter = "'LastName' Like 'O%'"    view2.RowFilter = "'FirstName' Like 'E%'"    Dim i As Integer    Debug.WriteLine("All LastNames starting with 'O'")    For i = 0 To view1.Count - 1       Debug.WriteLine(view1(i)("LastName"))    Next    Debug.WriteLine("All FirstNames starting with 'E'")    For i = 0 To view2.Count - 1       Debug.WriteLine(view1(i)("FirstName"))    Next End Function



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net