parameter prefix '@' vs "?' with MySql

  • Thread starter Thread starter John Coltrane
  • Start date Start date
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
 
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)
____________________________________________________________________________________________
 
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
 
¤ 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)
 
Back
Top