Error In Like Operator The String Pattern Is Invalid
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more error in like operator the string pattern is invalid c# about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users
Error In Like Operator The String Pattern ' 0-9 ' Is Invalid
Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up issues with finding data with certain strings up vote 1 down vote favorite 1 I am trying to make this work but have been unlucky it is giving me th following error Error in Like operator: the string pattern '%testing : | / - “ ‘ & * # @%' is invalid. This search works as long as it doesnt contain a string as the one above.. This is my code for the search DataRow[] rows = GetAllItems.Select("Name like '%" + cleanedText + "%'"); I tried - Modified per cHaos (still errors though) string cleanedText = SearchText.Replace("\"", "\\\"").Replace("'", "''"); but no luck when i enter the following string in the search although i know it is in the data testing : | / - “ ‘ & * # @% Anyone has a nice suggestion Thank you c# asp.net escaping share|improve this question edited Oct 13 '11 at 19:57 asked Oct 13 '11 at 19:32 user710502 4,4291970134 Are you using a SQL database? –Oded♦ Oct 13 '11 at 19:34 Ummm... what does this do? sSearctText.Replace("\"", "\"")? –Mark Byers Oct 13 '11 at 19:34 1 You do realize that .Replace("\"", "\"") does nothing useful, right? Same with all the other backslashed replacements -- you're replacing wacky chars with the exact same char. You probably want .Replace("\"", "\\\"") and the like. –cHao Oct 13 '11 at 19:35 sSearchText is the original variable - cHao, i used that Replace("\"", "\"") and it actually fixed the issue of not finding items with " in it.. dunno why, but i see your point –user710502 Oct 13 '11 at 19:38 @cHao & Mark I changed sSearctText.Replace("\"", "\"")? to sSearctText.Replace("\"", "\\\"")? and still the same error. –user710502 Oct 13 '11 at 19:45 | show 2 more comments 1 Answer 1 active oldest votes up vote 2 down vote accepted Both % and * can be used interchangeably for wildcard characters in the LIKE comparison. As such you will need to enc
0 verified answers | 4 Replies | 2 Followers ocornuau Points 990 Replied On: Thu, Oct 6 2011 8:59 AM Reply Hello,I have a webcombo Suggest That is type-ahead and bound to a DataTable (. Net). The problem Is That if I enter values of the format "'qqqq * k", an exception "Error in Like operator: the string pattern' qqqq * k% 'is invalid"Why?Is there a workaround?I tried with the event client "EditKeyDown" but I can not remove the characters "%" and "*".cordially Reply Post Points: 20 All Replies [Infragistics] Nikifor Tsvetkov Points 13,438 Replied On: Fri, Oct http://stackoverflow.com/questions/7759468/issues-with-finding-data-with-certain-strings 7 2011 9:03 AM Reply Suggested by [Infragistics] Nikifor Tsvetkov Hello Cornuau,Please take a look at the attached sample created with latest service release 11.1.20111.2064. Sample was tested with IE 9 and Firefox 7 and did not provided the misbehavior you faced. Please feel free to modify the sample or created a new one which reproduces the issue. Sincerely, Nikifor Developer Support Engineer Infragistics, http://www.infragistics.com/community/forums/t/60671.aspx Inc. www.infragistics.com/support 74313_WC.zip Reply Post Points: 20 ocornuau Points 990 Replied On: Mon, Oct 10 2011 5:11 AM Reply Hello,I use version 11.1.20111.2020. The WebCombo is associated with an object "asp: ObjectDataSource" owned "SelectMethod" uses a method that returns a DataSet.cordially Reply Post Points: 35 [Infragistics] Nikifor Tsvetkov Points 13,438 Replied On: Tue, Oct 11 2011 8:53 AM Reply Suggested by [Infragistics] Nikifor Tsvetkov Hello Cornuau,Can you please modify the attached sample to reproduce your code. The reason for the issue could be due to the way ObjectDataSource is configured with functions for Update, Sort, Insert etc. Does this issue reproduce with all the browsers? I will have to reproduce the same behavior on my side and debug to see if the error is in our controls or wrong implementation from your side. I also recommend always updating to the latest service release.Looking forward to hearing from you. Sincerely, Nikifor Developer Support Engineer Infragistics, Inc. www.infragistics.com/support Reply Post Points: 5 [Infragistics] Nikifor Tsvetkov Points 13,438 Replied On: Mon, Oct 17 2011 10:02 AM Reply Hello,Please let me know if the issue still persist or if you have any further questions about
SQL Server 2014 Express resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums https://social.msdn.microsoft.com/Forums/en-US/b3f1f846-c0c0-4fff-98ca-17fdc64205cc/error-in-like-operator-expression?forum=adodotnetdataset Blogs Channel 9 Documentation APIs and reference Dev centers Retired content http://www.programmingforums.org/post246090.html Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: Error in LIKE Operator Expression Data Platform Development error in > ADO.NET DataSet Question 0 Sign in to vote I have a table in SQL SErver which has come computed columns: [IsRexam] AS (CASE WHEN [RexamID] LIKE '00000000[A-Z][A-Z]' OR [RexamID] LIKE '000000[0-9][0-9][0-9]W' THEN 1 ELSE 0 END), [PlantID] AS (CASE WHEN [RexamID] LIKE '000000[0-9][0-9][0-9]W' THEN Convert(int, SUBSTRING([RexamID],7,3)) ELSE NULL END), One is a simple bit flag error in like and the other actually converts out the last three digits into a number. Well, as I am designing the DataSet to interface with this database, I figured for most of my "computed" columns in SQL I could easily translate them to DataColumn.Expression values so that I could have my data updated realtime without having to save (update) the database with altered values. And since the are computed columns and read only anyway it wouldn't make a difference on the .Net side regardless. So, I started playing around with them and came up with: MyBase.Columns.Add(New System.Data.DataColumn(IsRexamColumnName, GetType(Boolean), "IIF([RexamID] LIKE '00000000[A-Z][A-Z]' OR [RexamID] LIKE '000000[0-9][0-9][0-9]W" & _ "', 1, 0)", System.Data.MappingType.Element)) MyBase.Columns.Add(New System.Data.DataColumn(PlantIDColumnName, GetType(Integer), "IIF([RexamID] LIKE '000000[0-9][0-9][0-9]W', Convert(SUBSTRING([RexamID],7,3), in" & _ "t), NULL)", System.Data.MappingType.Element)) The Actual strings as entered into the DataSet Designer are below IIF([RexamID] LIKE '00000000[A-Z][A-Z]' OR [RexamID] LIKE '000000[0-9][0-9][0-9]W', 1, 0) IIF([RexamID] LIKE '000000[0-9][0-9][0-9]W', Convert(SUBSTRING([RexamID],7,3), int), NULL) Everything seemed to be fine. But now I'm trying load the datatable and I'm suddenly getting an unhandled excep
to Page... Thread Tools Display Modes Aug 13th, 2013, 10:00 AM #1 mykhayl Newbie Join Date: Feb 2013 Location: Milano Posts: 8 Rep Power: 0 DataTable Select method error Hi guys, i have a little problem with Select method of DataTable. I suppose it's a bug but every information is appreciated. With this code: (Toggle Plain Text) DataTable t = new DataTable(); t.Columns.Add("one"); t.Rows.Add("hello"); t.Select("one like '%h%l%o%'"); DataTable t = new DataTable(); t.Columns.Add("one"); t.Rows.Add("hello"); t.Select("one like '%h%l%o%'"); In the last line of code we have a simple "like". This line throw an EvaluateException with message Additional information: Error in Like operator: the string pattern '%h%l%o%' is invalid. In the other tests, every "like query" with % in the middle of the pattern throw this exception Why? (Tested of .NET 3.5, .NET 4) __________________ "There's no point in being exact about something if you don't even know what you're talking about." JOHN VON NEUMANN mykhayl View Public Profile Find More Posts by mykhayl Aug 13th, 2013, 12:36 PM #2 Momerath Programmer Join Date: Feb 2011 Posts: 44 Rep Power: 0 Re: DataTable Select method error Try changing your second line to (Toggle Plain Text) t.Columns.Add(new DataColum("one", typeof(String))); t.Columns.Add(new DataColum("one", typeof(String))); Momerath View Public Profile Find More Posts by Momerath Aug 13th, 2013, 1:38 PM #3 mykhayl Newbie Join Date: Feb 2013 Location: Milano Posts: 8 Rep Power: 0 Re: DataTable Select method error With your solution I have the same error, because by default the datacolumn is of string type. __________________ "There's no point in being exact about something if you don't even know what you're talking about." JOHN VON NEUMANN mykhayl View Public Profile Find More Posts by mykhayl Aug 15th, 2013, 8:33 AM #4 The Dark Programming Guru Join Date: Jun 2005 Posts: 1,631 Rep Power: 14 Re: DataTable Select method error From the examples linked from the MSDN documentation (here: http://www.csharp-examples.net/dataview-rowfilter/): Quote: Operator LIKE is used to include only values that match a pattern with wildcards. Wildcard character is * or %, it