Solved

Sql parameter with a character single quote

Posted on 2016-08-28
18
34 Views
Last Modified: 2016-08-28
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
0
Comment
Question by:RIAS
  • 10
  • 8
18 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773905
put 2 : O''Neil
1
 

Author Comment

by:RIAS
ID: 41773906
Thanks .Even combobox is having same problem

 CmbClinic.Text = StrClinic
strclinic =o'chp
is giving error
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773917
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

0
 

Author Comment

by:RIAS
ID: 41773925
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 .
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773932
in vb.net? Which error? can you show more code because if your value containing a ' is in a variable, it should work.
0
 

Author Comment

by:RIAS
ID: 41773936
CmbClinic.Text = StrClinic.ToString
            CmbClinicId.Text = StrClinicIdClinic.ToString
            CmbCurrClinic.Text = StrClinicCurr.ToString

 StrClinic.ToString =o'abc

Error :incorrect syntax in the string
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773939
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

0
 

Author Comment

by:RIAS
ID: 41773940
Yes, it is vb.net
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773941
what about the remaining of my comment?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:RIAS
ID: 41773943
Error is unclosed quotation mark after  'O'
0
 

Author Comment

by:RIAS
ID: 41773946
how o assign it to delimiter
0
 

Author Comment

by:RIAS
ID: 41773951
This worked but CmbClinic.Text = StrClinic.Replace("'", "''")
but displaying O''Abc as combobox text rather than O'Abc
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773952
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 "
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41773953
>>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

0
 

Author Comment

by:RIAS
ID: 41773956
Eric,

CmbClinic.Text = StrClinic this gives the above error .
0
 

Author Comment

by:RIAS
ID: 41773962
Eric,
Apologies for the above comment.It did work .Thanks a ton.
Don't what happened but rebuid solved it .
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41773964
Do you have an event on CmbClinic? The error is not coming from this line but it might be triggered by this line. Your debugger is supposed to stop exactly on the line causing the error. What is that line?
0
 

Author Comment

by:RIAS
ID: 41773965
You are Genius.Yes,Figured it out it had a seelcted index chaged event which was firing a query to the database.
Fixed it .
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now