Updating in Access- quotes

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gimpeltf
Posts: 29
Joined: Wed Nov 08, 2006 5:14 pm

Updating in Access- quotes

Post by gimpeltf » Thu Jul 05, 2007 5:42 pm

I'm having trouble Updating a field when there's an apostrophe (single quote) in the field. The same code put directly into Access works fine so it has to do with the interface.

put "Update Campers Set LastName='" & fld LastName & "' where ID=" & fld WID & ";" into uQuery
put revdb_execute(tConnectionID,uQuery) into dummy

Of course, there would be a problem with unmatched quotes in the above if the Name was O'Boyle.
I've taken out the single quotes in the code and replaced with & quote.
the value in uquery wouls be
Update Campers Set LastName="O'Boyle" where ID=365;
This code would work directly in Access but returns an error of
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Any thoughts?

Gimp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Jul 06, 2007 10:17 am

Dear Gimp,

I'm not an experienced Access user, but don't you have to escape the additional quote in O'Neil? Are you sure Access understands if you exchange all apastrophes and double quotes?

Try

Update Campers Set LastName='O\'Boyle' where ID=365;

(I believe it is a backslash, it might be a slash).

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gimpeltf
Posts: 29
Joined: Wed Nov 08, 2006 5:14 pm

Post by gimpeltf » Sat Jul 07, 2007 4:46 am

Mark wrote:Dear Gimp,

I'm not an experienced Access user, but don't you have to escape the additional quote in O'Neil? Are you sure Access understands if you exchange all apastrophes and double quotes?

Try

Update Campers Set LastName='O\'Boyle' where ID=365;

(I believe it is a backslash, it might be a slash).

Mark
Thanks but "O'Neil" works within access but not within revolution. I tried the escaping with a slash but it didn't help.

gimpeltf
Posts: 29
Joined: Wed Nov 08, 2006 5:14 pm

Post by gimpeltf » Sat Jul 07, 2007 5:18 am

I think I found the solution. I just found out that two consecutive single quotes is treated by Access as one single quote. Therefore, by replacing any quotes in a field with pairs of quotes will allow the proper passing of the string query parameter and the final value seen in Access has only one quote.
And thanks, because your suggestion led me to the answer.

Post Reply

Return to “Databases”