HANDLING ATA WITH SINGLE APOSTHROPE

Hi All,

I have data with single apostrophe inside it.

How to handle with those data ?

Thank you.
LVL 1
emi_sastraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.