Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to handle “apostrophe in a string” problem in MS SQL Server Insert Command

Author: DevASP

In this simple article you will learn that how you can insert a apostrophe in a database with help of simple VB.Net command.

When creating SQL statements, string values are delimited using apostrophes. So what happens when there is an apostrophe in the data you are trying to insert.

 

INSERT INTO DevASPtable (phrases) VALUES ('DevASP’s articles')

“DevASP’s articles”  here u see there is a apostrophe in the string now it generate an syntax error due to this it crash your software. So how can you handle this problem using a simple command.

To insert an apostrophe into the database using SQL you need to "double-up" the apostrophes. That is, put two apostrophes in the text where you want just one. For example, to insert the phrase " DevASP’’s” articles into a database, the SQL code looks like:

INSERT INTO DevASPtable (phrases) VALUES (' DevASP’s articles ')

Now here is a simple command in VB.Net with which you can resolve this problem:

Dim str as String=“DevASP’s articles”

str.Replace(”’”,”’’”)

 

Now your string change into double apostrophes sign string mean DevASP’s articles

Note: This does not insert two apostrophes into the database

Article Comments
Thank you for this article.

Posted on 8/21/2008 2:38:29 AM by Shree

how about if many apostrophe in a words ?

Posted on 2/22/2010 11:56:40 PM by corn

may be char(39)..

Posted on 5/4/2010 8:26:40 AM by Tanya

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Check the size of each table in your Database

Disclaimer - Privacy
© 2002-2017 DevASP.net