embedded single quotes 
Author Message
 embedded single quotes

How do I rebuild a string that has embedded quotes in it to allow me to
filter rows of a dataset?

For example:
Dim irows As DataRow()

Dim irow As DataRow

Dim pkfilterstring As String

pkfilterstring = "pname = '" & contactlistbox.SelectedItem & "'"

irows = dsprinter.Tables(0).Select(pkfilterstring)

This last line works fine for most circumstances; however, if
contactlistbox.selecteditem = "Perry Judd's Office" it fails because of the
embedded single quote in "Judd's".  How do I rebuild this string to make it
work?

Any help would be much appreciated.

Bernie Yaeger



Tue, 02 Aug 2005 13:54:36 GMT  
 embedded single quotes
I was doing this just the other day :)

Use double quotes for the SQL statement, i.e.:

pkfilterstring = "pname = """ & contactlistbox.SelectedItem & """"

which makes:

  pname = "Perry Judd's Office"

To put double quotes in a vb string, you just us two double quotes right
next to each other. As I have done above. If you say x = """", then x is
just one double quote.

--
Daniel Okely
dbokely at yahoo.com.au


Quote:
> How do I rebuild a string that has embedded quotes in it to allow me to
> filter rows of a dataset?

> For example:
> Dim irows As DataRow()

> Dim irow As DataRow

> Dim pkfilterstring As String

> pkfilterstring = "pname = '" & contactlistbox.SelectedItem & "'"

> irows = dsprinter.Tables(0).Select(pkfilterstring)

> This last line works fine for most circumstances; however, if
> contactlistbox.selecteditem = "Perry Judd's Office" it fails because of
the
> embedded single quote in "Judd's".  How do I rebuild this string to make
it
> work?

> Any help would be much appreciated.

> Bernie Yaeger



Tue, 02 Aug 2005 18:24:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need to embed single quote in SQL string

2. Help!!!: Tables With Embedded Single Quotes

3. Embedded single quote

4. Single Quotes converted to double Single Quotes

5. How to embed both single and double quotes in strings

6. Single Quote (Apostrophe) in Embedded Query?

7. Single quotes and double quotes

8. Double Quotes, Then Single Quotes, what comes next?

9. Double Quotes, Then Single Quotes, what comes next?

10. Double Quotes, Then Single Quotes, what comes next?

11. Double Quotes, Then Single Quotes, what comes next?

12. Double Quotes, Then Single Quotes, what comes next?

 

 
Powered by phpBB® Forum Software