index > .NET Framework Data Access and Storage > How to perform a case insensitive filter when the DataTable has C...

How to perform a case insensitive filter when the DataTable has C...

I have a grid bound to a DataView. The underlying DataTable has case sensitivity turned on because the SQL 2005 database uses the Latin1_General_BIN (case sensitive) collation.

When I build a RowFilter expression using LIKE, it is treated as case sensitive, but I want to be able to do case insensitive filtering. I experimented using a ">=" AND "<" expression, but then I lose wild card capability and I can't use that approach if I want to find all rows with data greater than (or less than, etc) a specified string.

Any suggestions will be appreciated. Thanks in advance.




VB .NET developer and instructor
JohnnieK
Try setting the DataTable.CaseSensitive property = False


Brad Roberts
Brad Roberts
I had tried that. It throws an exception. I tried absorbing the exception and going on but it had no effect. Thanks tho.


VB .NET developer and instructor
JohnnieK
I revisited that and I could avoid the exception by turning off AllowAddNew, AllowDelete and AllowUpdate before changing CaseSensitive. But still a simple "RowFilter=[Description] LIKE 't*'" will match entries beginning with "t" but not "T".


VB .NET developer and instructor
JohnnieK

Odd, the docs for the DataColumn.Expression property state....

To concatenate a string, use the + character. The value of the CaseSensitive property of the DataSet class determines whether string comparisons are case-sensitive. However, you can override that value with the CaseSensitive property of the DataTable class.




Brad Roberts
Brad Roberts

This is our code:

' Temporarily suspend adding new rows. Re-allow it when they're not filtering.

Grid.AllowAddNew = False

Grid.AllowDelete = False

Grid.AllowUpdate = False

Try

CType(BindingSource.DataSource, DataView).Table.CaseSensitive = False

Catch EX As Exception

Debug.WriteLine("Constraint exception setting CaseSensitivity to False: " & EX.Message)

End Try

BindingSource.Filter = rowFilter




VB .NET developer and instructor
JohnnieK

If all else fails...you can do something like...

use "Select t.*, Upper(coalesce(t.[Description],'')) as UpperDescription from table1

for selection then filter on the pseudo-field.




Brad Roberts
Brad Roberts
Thanks Brad. I'm going to keep fishing. We want to avoid returning to the database and some of our table are big (>30,000 rows with dozens of string columns), so we don't want to create virtual columns if we can help it.


VB .NET developer and instructor
JohnnieK
It turns out that the documentation is correct and I misled myself. The problem I had was that in the same routine I would disable case sensitivity, apply the filter, and then re-enable case sensitivity. When I watched what was happening in slow motion (the debugger), I initially had rows with mixed case, but when the case sensitivity was re-applied I lost some of those rows. Thus I had the perception that turning off case sensitivity wasn't working. Now I leave case-sensitivity turned off until it is needed (which in my case is when the user initiates add mode).


VB .NET developer and instructor
JohnnieK
reply 9

You can use google to search for other answers

 

More Articles

• SQL Server 2005 JDBC Driver and x64 systems
• HOT FIX K921883
• Sql database network connection
• Parameter within WITH-Clause in MDX
• Copying tables from a dataset to a SQL Table
• Database Structure design and User Interface Design
• Seek suggestion on .NET support options
• Help with queries
• Same Problem on using System.Transactions
• Parameters.AddWithValue Output parameter in ADO.NET 2
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Determine Primary Keys using SqlConnecti
• There is already an open DataReader asso
• Client to DLL that connects to a SQL Ser
• my sql
• Merging two datatables with different co
• What am I doing wrong?
• Visual Studio 2005
• Number of Query values and destination f
• Microsoft.ApplicationBlocks.Data.SqlHelp
• Client Server Application question, Plea
• Build connection string like COM?
• Oracle stored procedure design time supp
• how to open excel file (on server), writ
• oracleCommand error
• TransactionScope, Transactions and MSDTC

Hot Articles

• HOT FIX K921883
• Could not find stored procedure 'dbo.asp
• sqlserver 2005 connection with vb expres
• ADO.Net-Insert, Update, and Deleting Rec
• Determination of Business Logic location
• DataGridView vs DataGrid vs VB6 DataGrid
• jro.refreshcache on oledbconnection??? (
• [C# 2.0] ControlState
• ADO Recordset Getting Closed in C#
• Help trying to Insert to Access DB with
• Client to DLL that connects to a SQL Ser
• VB.NET Front end for small amount of XML
• Confused on the setup of VS with SQL Ser
• How to call a aspx page from a exe file
• Serializing an Object into a database Co

Recommend Articles

• OdbcConnection problem
• Problem with Transactions C# and Sql Exp
• need help inserting into a dbf file
• FAQ
• Datatable: works in windowsApp, not in A
• DataView with DateTime comparation
• Login Controls Visual Studio 2005 Wizard
• subquery doesn't work (using VC#, *.csv,
• Images from the database
• Internet Explorer VS Firefox
• [OTP]mouseover and open new page
• Architecture
• informix: exist a wizard to create datas
• SQLDataReader.GetOrdinal() fails rarely
• Master Detail Records