Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert the data into database.The data contains special symbols like this '.
I am getting error.I applied addslashes method.Still i am getting an error.How can i solve it.
Posted
Updated 25-Apr-12 1:27am
v2

What you need to do is convert each single apostraphe into a pair of apostraphes. I did this using the replace function in VBScript. It looked something like this:

SQL
name = name.Replace ("'","''")


SQL Server will interpret a pair of apostraphes as a single apostraphe in the database. The replace statement works just fine even if there are no apostraphes in the string. This should work equally well for Visual Basic or any other development tool.

The SQL syntax to insert a string like this looks something like:

SQL
INSERT Table1 (columnName)
VALUES ('Merlin D''Souza')


This will insert a single quote or apostrophe into the field between the "D" and the "S".
 
Share this answer
 
mysql_real_escape_string will do the trcik.
C++
//definition
unsigned long mysql_real_escape_string(
MYSQL *mysql, //pointer of mysql connection
char *to, //pointer of destination char array
const char *from, //source character array
unsigned long length//length of character array. not a single byte more
)


oh by the way, if it is php then
PHP
mysql_real_escape_string($val, $conn);
 
Share this answer
 
v2
given info is not sufficient provide
some more info or
data which you are inserting
 
Share this answer
 
Comments
bbirajdar 25-Apr-12 9:24am    
Please post your question as comment .. not as solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900