Why double escape for apostrophe?

E

Earl

Anyone know why the RowFilter has to be double-escaped? Anticipating names
with apostrophes, a single escape does not provide the proper name to filter
on.

For example, this would cause an exception:
Dim strname As String
strname = txtContact.Text
strname.Replace("'", "''")
dv.RowFilter = "ContactFullName='" + strname + "'"

.... but this would provide the proper filter:
dv.RowFilter = "ContactFullName='"" + strname + ""'"

Note the comma before the double quotes on the inside before the apostrophe
and the double quotes after the apostrophe on the outside.
 
P

Patrice

Use :
strName=strName.Replace("'","''")

Keep in mind that strings are immutable i.e. are never changed that is the
Replace *function* returns a new string. It doesn't change the existing
string.
 
E

Earl

Thanks Patrice.

Patrice said:
Use :
strName=strName.Replace("'","''")

Keep in mind that strings are immutable i.e. are never changed that is the
Replace *function* returns a new string. It doesn't change the existing
string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top