OleDB parameterized query for Access Database

B

bob

Hi,
Its been a long time since I have had the joy of feeding parameterized
query CommandText strings to an OleDBCommand object.
I have tried all manner of versions of " update foo set bar = @bar
where id = @id"
I have wrapped the fields in square brackets and the parameters in
square brackets and all manner of other strange variations.
The ExecuteNonQuery fires but the table doesn't update.

Finally went back to the old standby of ? as parameter place holder
and relying on Parameters ordinal position in the collection.

Is it really still this primitive or am I just screwing up the syntax?

Thanks
Bob
 
S

Scott M.

With Access and OleDB Providers you can use either the ? or the @, but the
parameters MUST be added to the command's parameters collection in the same
order that they are referenced in the update statement.

-Scott
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,
Its been a long time since I have had the joy of feeding parameterized
query CommandText strings to an  OleDBCommand object.
I have tried all manner of versions of  " update foo set bar = @bar
where id = @id"
I have wrapped the fields in square brackets and the parameters in
square brackets and all manner of other strange variations.
The ExecuteNonQuery fires but the table doesn't update.

Finally went back to the old standby of ? as parameter place holder
and relying on Parameters ordinal position in the collection.

Is it really still this primitive or am I just screwing up the syntax?

Thanks
Bob

Hi,

Unfortunatelly it's :(
 
B

bob

Hi Scott,
Thanks for your reply.
I'll leave the question marks in place to remind me that ordinal
position is important.
regards
Bob
 
B

bob

Hi Ignacio,
Thanks for your reply.
Scott says you can actually use named parameters but yes ordinal
position must be watched. I am going to stick with the question marks
so I don't fall for the same trap again.
regards
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top