[RESOLVED] problem inserting/updating
Hello,
I get a syntax error when insurting,updating my database if a user uses an apostrophie.
ie: there's
i seem to remember at college they told us there was somthing you could put after the string to remove the apostrophies but i cant for the life of me remember what it was!
does anyone out there know how to remedy my problem???
any help woulod be great!
thanks,
Iain
Re: problem inserting/updating
Can you tell the DB that you are using???. If its MSAccess / SQL Server you need to use the square brackets like.... [world's].
Re: problem inserting/updating
how i'm doing it is the user fills in a richtext box in my .net program the data they have entered is given to a string vairable and this vairable is entered into the database via an sql command.
if i put a square round my vairable it will insert the whole string and not mess of because of the apostrophes?
Re: problem inserting/updating
Try using the Double single quote for having single quote in your data.
Try searching your text for single singlequote and replace it with double singlequote
Re: problem inserting/updating
We could probably write a book just on how many times this particular question has been asked.
If you do a search on this subject, you will get a ton of returns and answers. In addition, I believe this is covered in our Database FAQs.
Re: problem inserting/updating
i'm not sure how i go about searing my string and replacing the apostrophe with a double single quote.
could you please post an example
Re: problem inserting/updating
Actually it's better if you don't do that.. it only solves one of the potential problems, and it is very hard to tell what the others may be (it varies by database system and various other factors).
The safest way to go is to use a Command object and put the values in via Parameters, which will also solve all of those other issues for you (without you even knowing what they are!). jmcilhinney posted an example in another one of your threads, here
As a bonus, you don't need to worry about delimiters or formatting dates etc, as it will automatically fill them in for you, as appropriate for the database system you are connected to!
Re: problem inserting/updating
Thank you all very much for your help!
Got it sorted now