Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
HI,

I want to know anyone else know how to insert values like "don't" or "can't" to sql server by using VB.NET of C#

The problem is because if I do like this:

SQL
sql = "INSERT INTO table (name, email, description) VALUES ('myname', 'email', 'I can't insert here with don't or can't with the word has ' in it')"


so is there anyone who know how to solve this problem?

Thank you indvance.
Posted
Updated 29-Oct-15 15:59pm
v2

Google for two things. First, "Sql Injection Attack" to find out why what you're doing is so dangerous to your database and then "C# sql parameterized query" to find out how to mitigate that problem to a very large degree and fix your INSERT problem at the same time.
 
Share this answer
 
Yes, please follow the Solution #1. You can cause the SQL Injection[^]. Always go with parameterized query.

And the solution:
SQL
sql = "INSERT INTO table (name, email, description) VALUES ('myname', 'email', 'I can''t insert here with don''t or can't with the word has '' in it')"

You need to escape the single quote with the single quote ;)

Try this & let me know if it works.

-KR
 
Share this answer
 

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