Hyphens in Rowfilter query

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
AmyLAsked:
Who is Participating?
 
Pratima PharandeCommented:
Try directly like

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

or

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

0
 
Jeff CertainCommented:
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
 
AmyLAuthor Commented:
Unfortunately, I still get the same error. The code runs fine as long as the value of targetValue does not have a hyphen.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

I think you mean to say hypen meand "\" , is it?
0
 
AmyLAuthor Commented:
Hyphen meaning "-". The backslashes are there to escape the apostrophe.
0
 
AmyLAuthor Commented:
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
 
Pratima PharandeCommented:
What error you are getting ?
0
 
AmyLAuthor Commented:
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
 
Pratima PharandeCommented:
string targetValue = @"my-test";
dataView.RowFilter = @"ColumnA = \'" + targetValue + "\'";
0
 
AmyLAuthor Commented:
Hmmm....that looked promising, but same error. Now I'm starting to wonder if I'm the only one?
0
 
AmyLAuthor Commented:
Okay, I'm just stupid. Your simple test allowed me to find the real problem. Thanks!
0
 
Pratima PharandeCommented:
How the problem get sloved at the end ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.