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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting a colon into a database 1

Status
Not open for further replies.

mcallaghan

IS-IT--Management
Mar 22, 2005
43
US
This is a pretty simple question I think. I have a asp page where I am inserting a text into a mediumtext field. Lets just say the word is (we're). Whenever I insert a colon I get a error. It doesnt like it. I take the colon out and it works. Does anyone know of a work around.
 
That's not a colon, that's an apostrophe. this is a colon ":"
Anyway,how are you constructing your query?

If you know you are going to have an apostrophe in it, surround it in double quotes instead single ones:

INSERT INTO mytable WALUES ("5","somefiled contents","we're apsotrophe ' some more words can't"...);



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Typically escaping the character also works.

\'

Although you should always surround text with double-quotes as stated by vacunita.

Mark
 
or do it the standard sql way -- replace each single quote inside a string value with two consecutive single quotes
Code:
insert into persons (lastname) values ('O''Toole')
not only does this work in all databases (including mysql), it also means you won't have to unlearn some mysql-specific method when writing code for a new database system


:)

r937.com | rudy.ca
 
wow rudy, i never knew you could do that. Thanks for the tip.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top