parameter prefix '@' vs "?' with MySql

J

John Coltrane

I have found that when I use parameters I must prefix the parameter name
with an '?', but I have 2 books that show '@' as the prefix. Is there a
reason for this? I am using C# with Mysql v5.1.

the following snippet works

statement = "select * from limbs where arms = ?arms";
using ( MySqlCommand command = new MySqlCommand(statement, conn) ) {
MySqlParameter param = new MySqlParameter();
param.ParameterName = "?arms";
param.Value = 0;
param.MySqlDbType = MySqlDbType.Int32;
param.Direction = ParameterDirection.Input;
command.Parameters.Add(param);
}

thanks for the help
 
W

William Vaughn \(MVP\)

If you're using a .NET native provider for MySQL then you might (just might)
be able to get away with named parameters. However, if you're using the
OleDB interface, parameters are positional (not named) and must be marked
with a "?" character.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
J

john coltrane

If you're using a .NET native provider for MySQL then you might (just might)
be able to get away with named parameters. However, if you're using the
OleDB interface, parameters are positional (not named) and must be marked
with a "?" character.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205  (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
___________________________________________________________________________­_________________









- Show quoted text -

I am using the native interface and the ? with a name, i.e. ?arm, is
required and will not work with an '@' symbol.

thanks for the help
 
P

Paul Clement

¤ I have found that when I use parameters I must prefix the parameter name
¤ with an '?', but I have 2 books that show '@' as the prefix. Is there a
¤ reason for this? I am using C# with Mysql v5.1.
¤

You would have to ask the MySQL folks about this. Native providers sometimes use their own syntax.
The question mark before the parameter name is not an ADO.NET syntax implementation.


Paul
~~~~
Microsoft MVP (Visual Basic)
 

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