[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

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
0
AmyL
Asked:
AmyL
  • 6
  • 5
1 Solution
 
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
 
Pratima PharandeCommented:
string targetValue = "my-test";
dataView.RowFilter = "ColumnA = \\'" + targetValue + "\\'";

I think you mean to say hypen meand "\" , is it?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
Pratima PharandeCommented:
Try directly like

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

or

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

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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now