Click here to Skip to main content
11,478,642 members (65,346 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 23:18pm
sufiki158
Edited 17-Sep-11 23:41pm
Mehdi Gholam275.3K
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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 209
1 F-ES Sitecore 170
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,865
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,059
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 18 Sep 2011
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