RowFilter and stackoverflow

  • Thread starter Thread starter Gene Ariani
  • Start date Start date
G

Gene Ariani

Is there a limit to how big a rowfilter on dataview could be? my rowfilter
is dynamically generated and if its get too big I get a stackoverflow error
other wise it works fine.
Any direction is appreciated it.
 
Gene:

I don't know of any off of the top of my head but let me make sure i
understand the question - are you asking about how many 'and's and ors you
can link together in setting the rowfilter? Unless you have some 90
condition statement, I'm guessing it's probably something else. Can you
post a sample of what the rowfilter looks like that's causing the problem?

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Thanks for the reply.

I have two dataset which contain both first and last names. I needed to
create a third dataset based on the common data where first and last names
are equal so I added:

DS.Relations.Add("Relation", New DataColumn()
{DS.Tables("Deployed").Columns("Last"),
DS.Tables("Deployed").Columns("First")}, New DataColumn()
{DS.Tables("Candidate").Columns("Last"),
DS.Tables("Candidate").Columns("First")})

Now I try to retrieve this data by creating a row filter

Dim FilterBuilder As New System.Text.StringBuilder
For Each ParentRow In DS.Tables("Deployed").Rows
For Each ChildRow In ParentRow.GetChildRows("Relation")
If FilterBuilder.ToString = "" Then
FilterBuilder.Append("Last= '" + ChildRow("Last").ToString + "' AND First=
'" + ChildRow("First").ToString + "'")
Else
FilterBuilder.Append(" OR " + "Last= '" + ChildRow("Last").ToString + "' AND
First= '" + ChildRow("First").ToString + "'")

End If
Next
Next

'Create the filtered dataview
Dim myDataView As DataView = DS.Tables("Deployed").DefaultView
myDataView.RowFilter = FilterBuilder.ToString


Now if the filter is not that big it works fine but when the text for the
filter gets big I get the stackoverflow error.


Thanks
 
Gene,
As I stated in the other newsgroup, your expression is too complex for the
RowFilter.

A couple of workaround ideas:

The first thing I would try is to add parentheses to your expression.
Something like:

(last = 'Harlow' and first = 'Jay') or (last = 'Ariani' and first =
'Gene')

If the continues to fail I would considering adding a new Boolean column to
your dataset. Which I used to filter on. Before I filtered I would use code
similar to:

For Each row As DataRow in DS.Tables("Deployed").Rows
Dim myDataView As DataView = DS.Tables("Deployed").DefaultView
myDataView.RowFilter = "selected = True"

The caveat of the second method is that each row will be modified, possible
causing problems with DataAdapter.Update.

A third method may be to use an ID column in the filter expression that you
are building, then you can safely use a single In expression. (add an
AutoIncrement column to the Deployed table, then use this ID as the
selection criteria).

Hope this helps
Jay
 
Gene,

As you know I completly agree with Jay in this.

What I all the time are curious for is if this dataview has to by dynamic,
what would lead to your approach, or that it is more static.

In the last case I would just create my own filter arraylist and create a
new datatable using that filter arraylist by copying the datarow.arrayitems
that fullfill the items in the araylist, that is much more simple and easier
to debug .

Just my thought,

Cor
 
Cor,
Actually creating a new DataTable might be a good alternative also. Not sure
if he needs an ArrayList per se.

Giving Gene's original code:

Dim filteredTable As DataTable = DS.Tables("Deployed").Clone()
For Each ParentRow In DS.Tables("Deployed").Rows
For Each ChildRow In ParentRow.GetChildRows("Relation")
filteredTable.ImportRow(ParentRow)

Next
Next

Hope this helps
Jay
 
Thanks everyone for their help.

I have tried In Select soultion with one criteria and it si working. I will
try datatable solution also.
 
Back
Top