Click here to Skip to main content
11,581,353 members (58,431 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ADO.NET
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

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 17-Sep-11 22:18pm
sufiki159
Edited 17-Sep-11 22:41pm
Mehdi Gholam280.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 | :laugh:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 260
1 Sergey Alexandrovich Kryukov 155
2 virusstorm 114
3 Frankie-C 105
4 RyanDev 84
0 OriginalGriff 1,183
1 Sergey Alexandrovich Kryukov 825
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 26 Jun 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100