Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I have small doubt. When user enters the ' (single quotes) in the text field.
While inserting in Table, it give us the error.
But I have seen in few sites eg- Facebook,Code Project where they allow ' (single quotes) and display the same.
Can anyone guide me on this.
Posted

Omit the id column altogether, it will be populated automatically. To use your variable, you should parameterise your SQL query.

Reference :

insert-data-into-sql-server-from-c-sharp-code

single-quotes-escape-during-string-insertion-into-a-database

cmd.Parameters.Add("@name", SqlDbType.VarChar);
 
Share this answer
 
You have to escape the single quote, that is turn a single quotes ' into double single quotes '', then you can insert as single quote into a table. Please check out this article:

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx[^]
 
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