Dataview.RowFilter question

dgorka

Well-known member
Joined
Dec 27, 2006
Messages
88
Programming Experience
5-10
I wasn't quite sure where to put this so I decided that it should work as a general question.

I have a XML file that I've loaded into a strongly typed dataset and am now trying to query against using a dataview. It's loading everything into the dataview and i'm able to loop through it, but my rowfilter doesn't seem to work. When I go to loop through it returns all rows from the dataset, not just the result set that I'm expecting. Here is my code:

VB.NET:
    Private Sub createMultiTiffs(ByVal outputDirectory As String)
        'this sub will create the multipage tiffs for output

        Dim view As DataView = New DataView
        With view
            .Table = typedBatchData.Tables(0)
            .AllowDelete = True
            .AllowEdit = True
            .AllowNew = True
            .RowFilter = "deleteFlag = false"
            .RowStateFilter = DataViewRowState.ModifiedCurrent
            .Sort = "docNumber"
        End With

        For Each dr As DataRow In view.Table.Rows
            'For testing that I'm looping through. Its grabbing all my records though
            MessageBox.Show("Image Name: " & dr.Item(0).ToString & vbCrLf & "DeleteFlag: " & dr.Item(1).ToString)
        Next


    End Sub

Here is a sample of what my XML file looks like:

VB.NET:
<batchItems>
  <imageXML>
    <origName>C:\Test\0001A01.TIF</origName>
    <deleteFlag>false</deleteFlag>
    <docNumber>8675309</docNumber>
  </imageXML>
  <imageXML>
    <origName>C:\Test\0001A02.TIF</origName>
    <deleteFlag>true</deleteFlag>
    <docNumber>1234567</docNumber>
  </imageXML>
</batchItems>

typedBatchData is my strongly typed dataset. Basically, I only want it to return rows where the deleteFlag field is false (I've also tried putting false in single quotes and got the same results as without), yet when i go through it returns everything. And I know that instead of using a DataRow in my loop, I should be using 'For Each dr As DataRowView in view', but when i tried that it basically said there was nothing there and skipped to 'End Sub'. So I guess another question I have is why thats not working.

Any help you can give me would be very appreciated. This is my first time working with dataviews and while I think I have some of the basics down, I'm feeling lost right now. Thanks
 
Right...

Your table has 1000 rows
Your view shows 100 of them

but view.Table refers to the TABLE, which has 1000 rows.. :rolleyes:


If you only want to work with rows that have a certain parameter do this:


Dim rows() as DataRow 'array
rows = myTable.Select("[DeletedFlag] = False")
'now rows is an array of all rows that match the criteria you set
 
Back
Top