Cannot interpret token "" at position 14

Hello.  I am still a bit unfamiliar with accessing databases the way I am doing here...so I'm probably missing something obvious...but here's the problem:

This line of code works fine:
            foundRows = testds.Tables(0).Select("(Control = '" & iControl & "') AND KeywordHits = '" & sKeyword & _
                "' AND KeywordList = '" & sKeywordList & "' AND FieldUpdated = '" & sFieldUpdated & "'")

Except when sKeyword is a string that contains a single apostrophe mark.  Example:  sKeyword = "abc w/2 d'ef"

So I tried changing that part of the Select string to use double-quotes around sKeyword instead of single-quotes.  Like this:
            foundRows = testds.Tables(0).Select("(Control = '" & iControl & "') AND KeywordHits = " & chr(34) & sKeyword & _
                chr(34) & " AND KeywordList = '" & sKeywordList & "' AND FieldUpdated = '" & sFieldUpdated & "'")

That didn't work.  I got a "Syntax error: Missing operand after 'w' operator."  I'm assuming this is referring to the w in the sKeyword variable, which is immediately followed by a /.  I don't know if the / is causing problems, or what.

So then I tried various things similar to this:
            foundRows = testds.Tables(0).Select("([Control] = " & Chr(34) & iControl & Chr(34) & " AND [KeywordHits] = " & _
                Chr(34) & sKeyword & Chr(34) & " AND [KeywordList] = " & Chr(34) & sKeywordList & Chr(34) & _
                " AND [FieldUpdated] = " & Chr(34) & sFieldUpdated & Chr(34) & ")")

And I now get this error message:
Cannot interpret token '"' at position 14.  (That's a single quote, double quote, single quote.)

I'm wondering now if double-quotes can't be used anywhere in the select statement.  If that's not the problem, why am I getting this error?  If that is the problem, how do I pass the string that includes a single quote if I'm using single quotes to surround the values I'm passing?

Thanks in advance for your help!!!
LVL 1
neo37Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AdsBCommented:
inside a string literal, when you need an apostrophe, try doing two apostrophes one after the other like this: ''

this is not the same as a double quote mark, like this: "

try this technique in your first example.

Also, you can use:
   sKeyword = Replace(sKeyword, "'", "''")     <--  replaces any single apostrophes with two apostrophes.
to douuble-up all the embedded single quotes before setting up your "Select" command.

Try that

AdsB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
Are you still having a problem with this, or is it solved?
0
neo37Author Commented:
Thanks for your help AdsB!  That worked beautifully.  Sorry it took me so long to accept the answer.  My schedule's been really hectic lately, and after I tried your suggestion I completely forgot about coming back here.  I just now remembered when I got the e-mail notification that another comment had been posted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.