Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
can someone tell that how to insert text with apostrophy sign in database in vb.net


Thanks
Posted

Parameterize Queries! Google for it! Use the SqlParameter, OleDbParameter, or OdbcParameter classes, depending on your database. That's what they're there for.

Then you don't have to worry about escaping these things!
 
Share this answer
 
Comments
Gregory Gadow 19-Apr-11 9:36am    
Yup, this is my preferred solution. I believe it has the added advantage of protecting against injection attacks.
You have to escape the character. Google is your friend:

"t-sql escape single-quote character" returned 37,200 results[^]
 
Share this answer
 
v2
You've to trim those specific values!

str="some sample image's to upload"
str = str.replaceof(" ' "," '' ")
 
Share this answer
 
You can insert by using .Replace("'","''");

eg:
SQL
"UPDATE [dbo].[Medium]
                                          SET [MediumName] = '{0}'
                                          WHERE MediumId= {1}", strMediumName.Replace("'", "''"), objMediumId


Try this
 
Share this answer
 
v2

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