[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

HANDLING ATA WITH SINGLE APOSTHROPE

Hi All,

I have data with single apostrophe inside it.

How to handle with those data ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 8
  • 6
  • 2
  • +1
1 Solution
 
emi_sastraAuthor Commented:
Is there any other way other than adding another apostrophe  ?

Thank you.
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, it is very easy.

When you pass any words into the query before passing it into the Sql server, the word replace(" ' "," ' ' "). Then after you pass the query, you not getting any error.
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, Specification is that, you have to replace the single quote with double quote at that time when pass the query into sql server.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emi_sastraAuthor Commented:
Is there any other way other than adding another apostrophe  ?

Thank you.

 

0
 
crafuseCommented:
not that i'm aware of. i've always done as samirbhogayta suggests.
0
 
CodeCruiserCommented:
Have you tried using parameters?
0
 
emi_sastraAuthor Commented:
Hi CodeCruiser,

 - Have you tried using parameters?
How ?

Thank you.
0
 
CodeCruiserCommented:
Where do you get the error? Any code?
0
 
emi_sastraAuthor Commented:
So far I know and have tried it is adding another apostrophe to the variable when query it.

I have heard about using parameter as you mention but have no idea about it.

Thank you.
0
 
CodeCruiserCommented:
Where do you get the error? Any code?
0
 
emi_sastraAuthor Commented:
There is no error.

Code :

strCustCode =replace(strcustCode,"''", "''")

"SELECT * FROM TMCUSTOMER WHERE CustCode = '" & strCustCode & "'"

I want to learn other method than add another aposthrope like parameter as you mentioned.

Thank you.
0
 
CodeCruiserCommented:
You can try

dbcmd.CommandText = "Select * From TMCustomer Where CustCode=@code"
dbcmd.Parameters.AddWithValue("@code", "My value's")
0
 
emi_sastraAuthor Commented:
dbcmd.CommandText = "Select * From TMCustomer Where CustCode=@code"
dbcmd.Parameters.AddWithValue("@code", strCustCode) <----- is okay ?

Why it works ?

Thank you.

0
 
CodeCruiserCommented:
>is okay ?
Yes

There are many advantages of using parameters

http://www.knowdotnet.com/articles/dynamicsqlparameters.html
0
 
emi_sastraAuthor Commented:
- You don't have to be plagued with Dynamic SQL Problems anymore.  The reason I built this tool is so that I could get rid of Dynamic SQL in my own applications.

Is it came with VS 2008 or need to install other software ?

Thank you.

0
 
emi_sastraAuthor Commented:
Hi CodeCruiser,

I get it now, it is came from VS.

Thank you very much for your help.
0
 
CodeCruiserCommented:
Glad to help :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 6
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now