Solved

Hyphens in Rowfilter query

Posted on 2007-11-26
12
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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