Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve data from dataviewmanager

Status
Not open for further replies.

Kalin

Programmer
Jul 24, 2001
76
NL
Hi,

I've got a dataviewmanager through which I filter some data in a dataset (multiple tables parent-child). So far so good. When I retrieve the data in a datagrid I get precisely the data I need but how can I retrieve this data programmaticaly ??

Thus step through the filtered dataset ??


Grtz,

Kalin
 
The "rows" in a DataView are of a different type than DataRow. You will need to access them like this:

Code:
'Initialized elsewhere
Dim dvw As DataView

For Each rvw As DataRowView In dvw
   Dim row As DataRow = rvw.Row

   'Access the row variable here like you normally
   'would a DataRow in a DataTable
Next
 
Hi Dalchri,

I've tried your solution but it gives me the following error...

An unhandled exception of type 'System.InvalidCastException' occurred in Proj18xx.exe

Additional information: Specified cast is not valid.

The code I wrote is:

Code:
Dim tabTiles As DataTable
Dim rowTile() As DataRow
Dim rowJunc() As DataRow
Dim rowConn() As DataRow
Dim strFilter As String

Dim dvmTiles As New DataViewManager
dvmTiles.DataSet = dsTiles
dvmTiles.DataViewSettings("tile").RowFilter = "ID = " & TileNumber

tabTiles = dvmTiles.DataSet.Tables(0)
rowTile = tabTiles.Select()
tabTiles = dvmTiles.DataSet.Tables(1)
rowJunc = tabTiles.Select()
tabTiles = dvmTiles.DataSet.Tables(2)
rowConn = tabTiles.Select()

For Each rvw As DataRowView In dvmTiles
    Dim row As DataRow = rvw.Row

    'Access the row variable here like you normally
    'would a DataRow in a DataTable
Next

The row table is the parenttable, both junction and connection are childtables.

I want to retrieve all rows in the childtables for one line in the tile table.

Grtz,

Kalin
 
As best I can see, the only way to get the DataView being used by the DataViewManager is through the CreateDataView method:

Code:
Dim tabTiles As DataTable
Dim rowTile() As DataRow
Dim rowJunc() As DataRow
Dim rowConn() As DataRow
Dim strFilter As String

Dim dvmTiles As New DataViewManager
dvmTiles.DataSet = dsTiles
'Explicitly create the DataView here if only
'so we can get a hold of it
Dim dvwTiles As DataView = dvmTiles.CreateDataView( _
   dsTiles.Tables("tile"))
dvmTiles.DataViewSettings("tile").RowFilter = "ID = " & TileNumber

tabTiles = dvmTiles.DataSet.Tables(0)
rowTile = tabTiles.Select()
tabTiles = dvmTiles.DataSet.Tables(1)
rowJunc = tabTiles.Select()
tabTiles = dvmTiles.DataSet.Tables(2)
rowConn = tabTiles.Select()

'If using the DataView that is created by the DataViewManager
'does not work, perhaps the DataViewManager is just
'using the default view???
'dvwTiles = dsTiles.Tables("tile").DefaultView
For Each rvw As DataRowView In dvwTiles
    Dim row As DataRow = rvw.Row

    'Access the row variable here like you normally
    'would a DataRow in a DataTable
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top