473,233 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

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 8493
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Heimer | last post by:
When I use the dataview.rowfilter and I try to display the field value of the first row, the code doesn't seem to show the first row AFTER the rowfilter. This is my code: DataView...
3
by: Randy | last post by:
Hello All, I'm trying to use a DataView and in the rowfilter, base it on two fields in the table. I can't find any examples on this. Is there a way to do it. I'm talking about something like......
1
by: Webgour | last post by:
I'm tring to filter a dataview with multiple rowfilters. The problem is that each time I use RowFilter on the DataView i'm quering the full dataview as it was loaded, not the filtered version. Is...
3
by: Vern | last post by:
The following code retrieves data into a dataset, and then creates a dataview with a filter. This dataview is then attached to a combobox. When the effective date changes, I would like to see the...
2
by: David | last post by:
Hi, I use DataView to filter my record. But when I use: ls_filter += " and DATEPART(hh, CA103)=" + i ; mydv.RowFilter = ls_filter; I got error. How should I filter by hour using...
3
by: Siegfried Heintze | last post by:
I'm displaying information on job postings in various cities. For example, might have a dozen jobs in Atlanta GA and I decide, at run time, that I don't want to see them. How do I set my DataView...
14
by: Able | last post by:
Dear friends Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers")) myDataView.RowFilter = "City = 'London'" My question is how to loop through all rows in myDataView and...
8
by: KC | last post by:
For a DataView.Rowfilter can I use more than one expression? I want to filter out two different things. For example can I take: dv.RowFilter = "MTX <> 'Customer Forcast'" and ...
3
by: =?Utf-8?B?cG1jZ3VpcmU=?= | last post by:
I have a dataset with 3 tables -- 2 Parent tables and 1 table that is a child table of both the parents. I create a dataview on the child table and set the rowfilter to a value which filters the...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.