Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert error into Access due to apostrophe...

Status
Not open for further replies.

martindavey

Programmer
Jan 2, 2000
122
GB
I am trying to insert into Access using C++

I have a variable that contains a surname that may well contain an apostrophe, eg. O'Reily.

My SQL insert string is:

"insert into [myTable] (Surname) ('%s')", ...

I get a syntax error on inserting because of the apostrophe in the surname.

I have tried using escaped quotes, and brackets but to no avail.

Removing the apostrophe is not an option.

Thanks, Martin :O|
 
try this

insert into [myTable] (Surname) (\"%s\")", ...


if this doesnt work, i will dig through my old code because I have dont this before.

Matt
 
DOH... might help if i read the post fully... i guess you have already tried that. Lemme see what I can find in my old code

Matt
 
I am surprised i found it this quickly... here ya go

char personName[128]; // assume it is O'Reily

what you need to do is (or at least what we did here at work)

modify personName to replace apostrophes with double apostrophes so O'Reily becomes O''Reily... but i am not sure how it will work for you. We are using an ORACLE database here.

Matt

 
By Jove you've got it!

Thanks for your persistance with this one, I've had very little response on other forums.

:O)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top