473,387 Members | 3,820 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,387 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 8498
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.