System.Data.EvaluateException
Hello,
I have a requirement, where in user types in a value and I use this value to filter my datatable and show the records to the user.
Below is the query.
strQueryExpression = "GradeDesc LIKE '" + strValue + "%'"; //strValue = the typed in value.
drFilteredRows = dtSourceDataTable.Select(strQuery);
While testing I typed a text like this "Shell[%%" and I got exceptions as below.
System.Data.EvaluateException Message: Error in Like operator: the string pattern 'Shell[%%' is invalid. Data: System.Collections.ListDictionaryInternal InnerException: NULL TargetSite: System.String AnalizePattern(System.String)
After analyzing and searching I found some solutions. Now I am replacing some of the characters woth proper escape characters. as below.
strValue = e.Text.Trim().Replace("'", "''"); //' is replaced by ''
strValue = strValue.Replace("[", "[[]");
But this is defenitely not sufficient.
For example when I type "Shell&*" or "Shell&" it works fine but when I type like this "Shell*&" this through the exception. How can I make handle these combination of characters?
Can any one help me in this regard?
|