Solved

Hyphens in Rowfilter query

Posted on 2007-11-26
12
469 Views
Last Modified: 2013-12-16
I get a runtime error if anything in my Rowfilter query (or dataTable.select query) contains a hypen. For example:

string targetValue = "my-test";
dataView.RowFilter = "ColumnA = \'" + targetValue + "\'";

Thanks!
Amy
0
Comment
Question by:AmyL
  • 6
  • 5
12 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 20355566
I'm not sure what the \ is for in your code. It looks like you've got a misplaced ' though.

I'd do something like this:

string targetValue = "my-test";
dataView.RowFilter = String.Format("ColumnA = '\{0}\'", targetValue);
0
 

Author Comment

by:AmyL
ID: 20355673
Unfortunately, I still get the same error. The code runs fine as long as the value of targetValue does not have a hyphen.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20355692
string targetValue = "my-test";
dataView.RowFilter = "ColumnA = \\'" + targetValue + "\\'";

I think you mean to say hypen meand "\" , is it?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:AmyL
ID: 20355700
Hyphen meaning "-". The backslashes are there to escape the apostrophe.
0
 

Author Comment

by:AmyL
ID: 20355711
For the sake of this question, the backslashes can be removed:

string targetValue = "my-test";
dataView.RowFilter = "ColumnA = " + targetValue;

Is everyone else able to have a hyphen in their query? Maybe I'm completely missing something.
The code works fine when it looks like this:

string targetValue = "mytest";
dataView.RowFilter = "ColumnA = \'" + targetValue + "\'";

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20355731
What error you are getting ?
0
 

Author Comment

by:AmyL
ID: 20355763
Syntax error: Missing operand after 's' operator.

(The letter 's' changes based on what the hyphenated value is. In the example, I'm guessing it would be 'y' or 't').
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20355770
string targetValue = @"my-test";
dataView.RowFilter = @"ColumnA = \'" + targetValue + "\'";
0
 

Author Comment

by:AmyL
ID: 20355808
Hmmm....that looked promising, but same error. Now I'm starting to wonder if I'm the only one?
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 125 total points
ID: 20355814
Try directly like

dataView.RowFilter = "ColumnA =my-test";

or

dataView.RowFilter = "ColumnA ='my-test'";

0
 

Author Closing Comment

by:AmyL
ID: 31411133
Okay, I'm just stupid. Your simple test allowed me to find the real problem. Thanks!
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20355898
How the problem get sloved at the end ?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question