Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2005, 09:41 AM
Registered User
 
Join Date: May 2005
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

 
Old May 23rd, 2005, 05:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
Old May 24th, 2005, 08:43 AM
Registered User
 
Join Date: May 2005
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

 
Old May 24th, 2005, 09:24 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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





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





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