468,738 Members | 1,761 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

using singe qoutation in DataView.RowFilter

Hi,
I need to use single qoutation ( ' ) in my filter string but I get error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
8 8369
Newbie,
You need to use two single quotation marks in the "mysearch" variable:

Something like
mysearch = "Bob''s book";
That's: B, o, b, single quote, single quote, s ...

Hope this helps
Jay

"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl... Hi,
I need to use single qoutation ( ' ) in my filter string but I get error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
newbie_csharp,

I believe you will have to double up on the quotes, like this:

// Alter the string so that it can be included in the filter.
filterString = mysearch.Replace(@"'", @"''");

An then search on that.

I personally don't like this, and have suggested a number of times to
people at MS that they provide something like parameters for this kind of
operation (so that we could pass CLR types and not have to worry about
conversions like this).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,
I need to use single qoutation ( ' ) in my filter string but I get error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
Nicholas,
Parameters or even simply an Encode/Escape function (like Regex.Escape &
Regex.Unescape) that properly encodes the string so it works correctly as a
"quoted" string in the filter.

One that properly, quotes: single quote, double quote, square bracket &
other characters to be used in the Filter & other properties of the DataSet
Object Model.

Hope this helps
Jay

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oy**************@TK2MSFTNGP09.phx.gbl...
newbie_csharp,

I believe you will have to double up on the quotes, like this:

// Alter the string so that it can be included in the filter.
filterString = mysearch.Replace(@"'", @"''");

An then search on that.

I personally don't like this, and have suggested a number of times to
people at MS that they provide something like parameters for this kind of
operation (so that we could pass CLR types and not have to worry about
conversions like this).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,
I need to use single qoutation ( ' ) in my filter string but I get error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #4
Jay,

I don't think that an escape function is enough, as it would still force
me to concatenate parts of my expression together, something I wouldn't have
to do for a command to a database.

And yes, anywhere the Expression property is relevant, and handles all
types in the framework that can be stored in a dataset.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Nicholas,
Parameters or even simply an Encode/Escape function (like Regex.Escape &
Regex.Unescape) that properly encodes the string so it works correctly as
a "quoted" string in the filter.

One that properly, quotes: single quote, double quote, square bracket &
other characters to be used in the Filter & other properties of the
DataSet Object Model.

Hope this helps
Jay

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@TK2MSFTNGP09.phx.gbl...
newbie_csharp,

I believe you will have to double up on the quotes, like this:

// Alter the string so that it can be included in the filter.
filterString = mysearch.Replace(@"'", @"''");

An then search on that.

I personally don't like this, and have suggested a number of times to
people at MS that they provide something like parameters for this kind of
operation (so that we could pass CLR types and not have to worry about
conversions like this).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,
I need to use single qoutation ( ' ) in my filter string but I get error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 16 '05 #5
Nicholas,
The escape function itself could do the concatenation, by accepting a format
string & params args, similar to String.Format.

Something like:
mysearch = "Bob's book";
dataView.RowFilter = Escape("myfield LIKE '{0}%'", mysearch);

Otherwise I totally agree, a full parameters collection would be better!

Jay

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OI**************@TK2MSFTNGP09.phx.gbl...
Jay,

I don't think that an escape function is enough, as it would still
force me to concatenate parts of my expression together, something I
wouldn't have to do for a command to a database.

And yes, anywhere the Expression property is relevant, and handles all
types in the framework that can be stored in a dataset.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Nicholas,
Parameters or even simply an Encode/Escape function (like Regex.Escape &
Regex.Unescape) that properly encodes the string so it works correctly as
a "quoted" string in the filter.

One that properly, quotes: single quote, double quote, square bracket &
other characters to be used in the Filter & other properties of the
DataSet Object Model.

Hope this helps
Jay

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Oy**************@TK2MSFTNGP09.phx.gbl...
newbie_csharp,

I believe you will have to double up on the quotes, like this:

// Alter the string so that it can be included in the filter.
filterString = mysearch.Replace(@"'", @"''");

An then search on that.

I personally don't like this, and have suggested a number of times to
people at MS that they provide something like parameters for this kind
of operation (so that we could pass CLR types and not have to worry
about conversions like this).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,
I need to use single qoutation ( ' ) in my filter string but I get
error
message. how can I do something like this:

mysearch = "Bob's book";
dataView.RowFilter = "myfield LIKE '" + mysearch + "%'";

even I changed "mysearch to this but still it's not working:

mysearch = "Bob\'s book";

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 16 '05 #6
Jay:

Shouldn't you be paying attention to the DevCon speaker instead of
hanging out in a newsgroup? :)

--
Scott
http://www.OdeToCode.com/blogs/scott/

P.S. No, I didn't make it there, but I am jealous.
Nicholas,
The escape function itself could do the concatenation, by accepting a format
string & params args, similar to String.Format.

Something like:
mysearch = "Bob's book";
dataView.RowFilter = Escape("myfield LIKE '{0}%'", mysearch);

Otherwise I totally agree, a full parameters collection would be better!

Jay


Nov 16 '05 #7
Scott,
?

I'm not at DevCon, so how would I be able to pay attention to the speaker?

Jay

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:2a********************************@4ax.com...
Jay:

Shouldn't you be paying attention to the DevCon speaker instead of
hanging out in a newsgroup? :)

--
Scott
http://www.OdeToCode.com/blogs/scott/

P.S. No, I didn't make it there, but I am jealous.
Nicholas,
The escape function itself could do the concatenation, by accepting a
format
string & params args, similar to String.Format.

Something like:
mysearch = "Bob's book";
dataView.RowFilter = Escape("myfield LIKE '{0}%'", mysearch);

Otherwise I totally agree, a full parameters collection would be better!

Jay

Nov 16 '05 #8
Opps - wrong Jay. Sorry for the confusion :)
On Wed, 20 Oct 2004 22:41:48 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
Scott,
?

I'm not at DevCon, so how would I be able to pay attention to the speaker?

Jay

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:2a********************************@4ax.com.. .
Jay:

Shouldn't you be paying attention to the DevCon speaker instead of
hanging out in a newsgroup? :)

--
Scott
http://www.OdeToCode.com/blogs/scott/

P.S. No, I didn't make it there, but I am jealous.
Nicholas,
The escape function itself could do the concatenation, by accepting a
format
string & params args, similar to String.Format.

Something like:
mysearch = "Bob's book";
dataView.RowFilter = Escape("myfield LIKE '{0}%'", mysearch);

Otherwise I totally agree, a full parameters collection would be better!

Jay


--
Scott
http://www.OdeToCode.com/
Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Randy | last post: by
1 post views Thread by Webgour | last post: by
3 posts views Thread by Siegfried Heintze | last post: by
14 posts views Thread by Able | last post: by
8 posts views Thread by KC | last post: by
3 posts views Thread by =?Utf-8?B?cG1jZ3VpcmU=?= | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.