Avatar of RIAS
RIAS
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Sql parameter with a character single quote

Hello,

How do I pass a sql parameter with a ' single quote .As soon I pass a parameter example @Ref as O'Neil it fails.

Cheers
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
RIAS

8/22/2022 - Mon
Éric Moreau

put 2 : O''Neil
RIAS

ASKER
Thanks .Even combobox is having same problem

 CmbClinic.Text = StrClinic
strclinic =o'chp
is giving error
Éric Moreau

Context please? Where is this code?

A string has to be placed between delimiters (and those delimiters varies according to the language or tool. With some tools it would be:
strclinic ="o'chp"

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
RIAS

ASKER
I am loding combo boxes with the values from database.
The values are o'Abc ,h'uim when I try to set text property I get an error .
Éric Moreau

in vb.net? Which error? can you show more code because if your value containing a ' is in a variable, it should work.
RIAS

ASKER
CmbClinic.Text = StrClinic.ToString
            CmbClinicId.Text = StrClinicIdClinic.ToString
            CmbCurrClinic.Text = StrClinicCurr.ToString

 StrClinic.ToString =o'abc

Error :incorrect syntax in the string
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

1- can you confirm it is vb.net?

2- You cannot assign a value to .ToString as Tostring is a method and cannot receive a value

3- as already said, a string value needs to be enclosed between delimiters:
 StrClinic = "o'abc"

Open in new window

RIAS

ASKER
Yes, it is vb.net
Éric Moreau

what about the remaining of my comment?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
RIAS

ASKER
Error is unclosed quotation mark after  'O'
RIAS

ASKER
how o assign it to delimiter
RIAS

ASKER
This worked but CmbClinic.Text = StrClinic.Replace("'", "''")
but displaying O''Abc as combobox text rather than O'Abc
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

you are not showing complete code! How am I supposed to guess what you are doing and what is your code? I have provided code that I know is working (StrClinic = "o'abc") and I don't event if you are using it and where you are using it.

I am more than please to help you but you really need to help me back!

And BTW, a delimiter is a character used to surround a string value which in this case is the "
Éric Moreau

>>This worked but CmbClinic.Text = StrClinic.Replace("'", "''")
>>but displaying O''Abc as combobox text rather than O'Abc

In this specific scenario, you don't need to double the quote. it should only be:
CmbClinic.Text = StrClinic

Open in new window

RIAS

ASKER
Eric,

CmbClinic.Text = StrClinic this gives the above error .
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
RIAS

ASKER
Eric,
Apologies for the above comment.It did work .Thanks a ton.
Don't what happened but rebuid solved it .
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RIAS

ASKER
You are Genius.Yes,Figured it out it had a seelcted index chaged event which was firing a query to the database.
Fixed it .