RE: Syntax error in insert statement?
- From: "Josh Hawley" <JoshHawley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 20:03:01 -0700
Yeah those are valid points. I have a piece of code that i wrote that handles
the ' chars, and security isnt an issue because no one but my code can
connect to the server. however this is not the case in other peoples
situations, so i probably shouldnt suggest it here.
can you point me to an example of c# code that uses the parameters?
"dkocur" wrote:
> Josh, Thanks for the reply. The ? are placeholders for parameters. There
> are numerous reasons for using parameters instead of building the string as
> you mention. I'll give you two:
>
> 1. Security. It prevents a SQL injection attack.
> 2. I don't have to format strings such as this one to insert them. (Note
> the apostrophe in the word don't.)
>
> I've managed to get it to work using named parameters, but I'd prefer to use
> unnamed parameters to maximize performance.
>
> "Josh Hawley" wrote:
>
> > I'm not sure why you are putting question marks in there...
> > I usually use a stringbuilder to make my queries, it helps alot...
> > escpecially when the queries get really long and complex (i have some that
> > are 4 pages long). something like this:
> >
> > string viewID="1";
> > string name="Josh";
> > string namespace="namespace";
> >
> > StringBuilder query=new StringBuilder();
> > query.AppendFormat("insert into BusDataObject (View_ID, Name, NameSpace)
> > Values ('{0}', '{1}', '{2}')", viewID, name, namespace);
> > // the {0} inserts the value into the string
> > // it is important to have single quotes around any string values to prevent
> > them from running too long
> >
> >
> >
> > "dkocur" wrote:
> >
> > > "insert into BusDataObject (View_ID, Name, NameSpace) Values (?, ?, ?);"
> > >
> > > results in "Incorrect syntax near '?'."
> > >
> > > I'm using C# Express Beta 1 with SQL Server. I know it has to be something
> > > simple, but I just can't figure it out.
.
- Follow-Ups:
- RE: Syntax error in insert statement?
- From: dkocur
- RE: Syntax error in insert statement?
- From: dkocur
- RE: Syntax error in insert statement?
- References:
- Syntax error in insert statement?
- From: dkocur
- RE: Syntax error in insert statement?
- From: Josh Hawley
- RE: Syntax error in insert statement?
- From: dkocur
- Syntax error in insert statement?
- Prev by Date: RE: incrementally increase value
- Next by Date: Re: incrementally increase value
- Previous by thread: RE: Syntax error in insert statement?
- Next by thread: RE: Syntax error in insert statement?
- Index(es):
Relevant Pages
|