Re: escape the ' and " chars to insert them onto an Access database
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 09/30/04
- Next message: James Curran: "Re: Passing parameters from a Web page to a custom control"
- Previous message: James Curran: "Re: Input string was not in a correct format"
- In reply to: Luminal: "escape the ' and " chars to insert them onto an Access database"
- Next in thread: Luminal: "Re: escape the ' and " chars to insert them onto an Access database"
- Reply: Luminal: "Re: escape the ' and " chars to insert them onto an Access database"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Sep 2004 11:30:13 -0400
Luminal,
Instead of trying to figure out the quotes yourself, I would recommend
using a parameterized query, and then just set the value of the parameter to
the value you have. The provider will take care of formatting the values
correctly.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Luminal" <luminal_NOSPAM@hotpop_NOSPAM.com> wrote in message
news:eKDKJHwpEHA.324@TK2MSFTNGP11.phx.gbl...
> Greetings
>
> I'm having some problems on my C# application. I'm using an access
> database and I'm not able to do select queries with the ' character.
>
> My code is this:
>
> // some previous code like open connection
>
> string sqlStatement="SELECT oid FROM formatos WHERE formato='cd\\'s'";
>
> myComm.CommandText=sqlStatement;
> OleDbDataReader myDR=myComm.ExecuteReader();
>
> //... and so on
>
> I get the exception message
>
> AccessException: Syntax error (missing operator) in query expression
> 'formato='cd\'s''.
> DeclaringType.FullName:: System.Data.OleDb.OleDbCommand
> Method - Void ExecuteCommandTextErrorHandling(Int32)
> at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
> hr)
> at
> System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS
> dbParams, Object& executeResult)
> at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&
> executeResult)
> at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior
> behavior, Object& executeResult)
> at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
> behavior, String method)
> at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior
> behavior)
> at System.Data.OleDb.OleDbCommand.ExecuteReader()
> at
> ...
>
>
> AccessError: Syntax error (missing operator) in query expression
> 'formato='cd\'s''.
> Source: Microsoft JET Database Engine
> Native Error: -524553244
> State: 3075
>
> How can I escape the ' and " chars so I can insert them onto an Access
> database?
>
> TIA
>
> Lum
- Next message: James Curran: "Re: Passing parameters from a Web page to a custom control"
- Previous message: James Curran: "Re: Input string was not in a correct format"
- In reply to: Luminal: "escape the ' and " chars to insert them onto an Access database"
- Next in thread: Luminal: "Re: escape the ' and " chars to insert them onto an Access database"
- Reply: Luminal: "Re: escape the ' and " chars to insert them onto an Access database"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|