Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everybody,

I have the following problem.

I have a large database table (inside a MS Sql-database) which I read inside a DataTable object. The DataTable object itself is bound to a DataGridView object where I show the data. Sometimes I would like to hide some data, which is not relevant for the current view. The DataView object inside the DataTable seems to be the best way to do this. DataView has a property RowFilter where you can set the visible rows. The input to RowFilter is a sql string. Unfortunately, I get a stack overflow exception when the string becomes too long. The following happens when then:

“An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll”

I have already tried to split the string and call RowFilter several times but this would override the old settings. The same happens when calling "Select" function from the DataTable object.

Do someone have a similar problem and find a solution.

Below, I have scheduled my code:

Thank you for all help

Sahit

C#
DataTable sourceTable = new DataTable(); 
SqlStringBuilder filter = new SqlStringBuilder();
// Set source from database

// Fill "filter" with a very large string
// Like {[intType = '1']} AND(intFamilyID = '2' OR intFamilyID = '4' OR 
   intFamilyID = '6') .........................} 
// 17 000 signs

// Here happens the problem
sourceTable.DefaultView.RowFilter = = filter.ToString();

// The same happens when trying this. 
DataRow[] resultSet = sourceTable.Select(filter.ToString());
Posted
Updated 17-Sep-11 22:41pm
v2

Its better to filter your query on the database side then show the results on your grid.

The database engine is designed to do this more efficiently.

Keep the RowFilter for simple filters once the results are back.
 
Share this answer
 
Don't do it that way at all - filter the rows coming from the database at source, instead of later. If you have a large database, then returning all the rows and filtering out those you dont want to display is wasteful of bandwidth, memory, and database server resources. It will also slow the display for the user.

Never return rows or fields you are not going to use, and never return more than a hundred or so rows if you can help it - think of the poor user wading through that amount of data!

In addition, it will probably get rid of your problem...:laugh:
 
Share this answer
 
I have little bit recover the issue by using 'IN' in my row filter expression.
I have tested and found no issue in-case the length of RowFilter expression is approx 75K.

Try by using 'IN' operator, hope it works for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900