Solved

Hyphens in Rowfilter query

Posted on 2007-11-26
12
466 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now