How to perform a case insensitive filter when the DataTable has CaseSensitive=True

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.

[620 byte] By [JohnnieK] at [2007-12-24]
# 1
Try setting the DataTable.CaseSensitive property = False
BradRoberts at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
I had tried that. It throws an exception. I tried absorbing the exception and going on but it had no effect. Thanks tho.
JohnnieK at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3
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".
JohnnieK at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4

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.

BradRoberts at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5

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

JohnnieK at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 6

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.

BradRoberts at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 7
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.
JohnnieK at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 8
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).
JohnnieK at 2007-8-31 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified