Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2005, 09:41 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add parameter val containing single quote

I am adding a parameter value to an OracleCommand parameter. If I add a value that does NOT contain a single quote, the query works and I get the expected results returned. If I add a value that contains a single quote, such as "'CJ','CL','CP'", I get ORA-01403 returned (no rows found). I have tried preceding each single quote with another single quote, preceding each single quote with a backslash, and each of these with preceding the entire string with '@'. None of these syntaxes work. It appears that ADO stops reading as soon as it hits the first single quote. I am working in Visual Studio .NET 2003 in C#. The where clause needs to search for multiple values (e.g., WHERE work_schedule IN ('CJ','CL','CP')).

I know that parameterized queries are the correct way to handle these queries, and I have been using them in C for years. I can't believe that there is no way to create a parameterized query in C# .net where the where clause must search for multiple values.

Does anyone know how to do this??

Thanks

Reply With Quote
  #2 (permalink)  
Old May 23rd, 2005, 05:53 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is a suitable command class to match the connection class you are using. The command class has a parameters collection which you can populate with the necessary values and parameter names (where usable). You'll need to read up on the right command class for the connection you're using (SqlConnect, OleDbConnection, etc). The way you structure a query differs based on the connection type.

-Peter
Reply With Quote
  #3 (permalink)  
Old May 24th, 2005, 08:43 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 There is a suitable command class to match the connection class you are using. The command class has a parameters collection which you can populate with the necessary values and parameter names (where usable). You'll need to read up on the right command class for the connection you're using (SqlConnect, OleDbConnection, etc). The way you structure a query differs based on the connection type.

-Peter
I am aware of the command class and the parameters colletion that goes with it. Please see the documentation at http://msdn.microsoft.com/library/de...eterstopic.asp. This works. The problem occurs when setting the .Value to a string that contains a single quote. The documentation states 'The user may be required to use escape character syntax if the stored procedure name contains any special characters.' I have found that this also applies to the string being passed to .Value. However, the escape characters I have tried (another single quote, backlash, '@') do not work. I need an alternate way to assign a string containing a single quote as a Parameter.

Thanks

Reply With Quote
  #4 (permalink)  
Old May 24th, 2005, 09:24 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

We have code that works with both MSSQL and Oracle (using the OleDbCommand/Connection). The only change I've found necessary is to modify a raw sql command to change ' to ''. The parameters are supposed to take care of this automatically so it's only necessary in concatenated command string. If the ' to '' change doesn't work for you than I don't know what the problem is.

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single quote in function Parameter ASP -Javascript Hem96 Classic ASP Professional 4 September 14th, 2007 09:10 AM
single quote problem harpua PHP Databases 1 July 8th, 2005 07:37 AM
replace single Quote qadeerahmad General .NET 3 September 6th, 2004 08:10 PM
problem caused by single quote isheikh BOOK: Beginning ASP 3.0 1 April 16th, 2004 02:52 AM



All times are GMT -4. The time now is 09:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.