Re: quotes into SQL query
From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 03/03/04
- Next message: Manch: "Trapping SQL Error Generated In Trigger"
- Previous message: Aaron Lind: "ForeignKeyConstraint & GetChanges"
- In reply to: Henry: "quotes into SQL query"
- Next in thread: Henry: "Re: quotes into SQL query"
- Reply: Henry: "Re: quotes into SQL query"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 3 Mar 2004 09:48:47 -0500
use Parameters instead.
cmd.CommandText = "INSERT INTO SomeTable Values (?, ?, ?)"
cmd.Parameters.Add(FirstValue)
cmd.Parameters.Add(SecondValue)
etc..
There are multiple overloads
http://www.knowdotnet.com/articles/parametergotcha.html and I'd recommend
using one of them because it gives you more control, but the example above
will work. This will give you cleaner code, better performance, and
improved security.... All upside on this approach.
HTH,
Bill
"Henry" <henriquebucher@hotmail.com.no_spam> wrote in message
news:#evJAkSAEHA.3220@TK2MSFTNGP10.phx.gbl...
> I'm writing a class that crawls through a removable media retrieving file
> info (who didn't make one yet?) and storing in an Access mdb.
> OleDbCommand fails when the file name contains quotes as in
> My friend's pictures.zip
> When building the SQL INSERT query, I tried putting \" before and after as
> suggested in a MS KB but it didn't work. I'm almost going to escape the
> entire file name a la http...
> Should I use stored procs and pass the file name as a parameter? Would it
> avoid escaping the file name?
>
> Many thanks
>
> Henrique
>
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.608 / Virus Database: 388 - Release Date: 3/3/2004
>
>
- Next message: Manch: "Trapping SQL Error Generated In Trigger"
- Previous message: Aaron Lind: "ForeignKeyConstraint & GetChanges"
- In reply to: Henry: "quotes into SQL query"
- Next in thread: Henry: "Re: quotes into SQL query"
- Reply: Henry: "Re: quotes into SQL query"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|