Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hyphens in Rowfilter query

Posted on 2007-11-26
12
Medium Priority
?
478 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 500 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

876 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