9 messages in com.mysql.lists.dotnetRe: Return parameter from query.
FromSent OnAttachments
Asbjørn Konstad24 Sep 2004 01:05 
Fredrick Bartlett25 Sep 2004 15:32 
Reggie Burnett26 Sep 2004 00:08 
Guy Platt06 Oct 2004 01:53 
Fredrick Bartlett06 Oct 2004 07:49 
Jordan Sparks06 Oct 2004 08:14 
Guy Platt06 Oct 2004 08:29 
Jordan Sparks06 Oct 2004 08:44 
Barry Zubel06 Oct 2004 08:44 
Subject:Re: Return parameter from query.
From:Fredrick Bartlett (palm@earthlink.net)
Date:09/25/2004 03:32:27 PM
List:com.mysql.lists.dotnet

This might apply here. Here is a quote from a previous post...

The syntax for setting parameters has changed. Now you use ? instead of @ to mark parameters. This change was necessary for proper compatibility with MySQL. However, realizing that people may have lots of code to change, I have included a connection string option that will enable the old syntax. Add "old syntax=yes" to your connection string and it will work. However, you should read the help on MySqlCommand. There is a note included that talks about the tradeoffs of doing this.

----- Original Message ----- From: "Asbjørn Konstad" <asbj@konstad.no> To: <dot@lists.mysql.com> Sent: Friday, September 24, 2004 1:05 AM Subject: Return parameter from query.

Hi.

Anyone as frustrated as me???

Problem:

I have a created a command to return maximum id from myTable.., like this:

//--------------------------------------------------------------------------

----------------------------------------------------------------------------

-----

MySqlCommand cmd = new MySqlCommand("SELECT @PAR := MAX(ID) FROM myTable", myConnection);

MySqlParameter param = new MySqlParameter();

param = cmd.Parameters.Add("@PAR", MySqlDbType.Int32, 4);

param.Direction = ParameterDirection.Output;

myConnection.Open();

cmd.ExecuteNonQuery();

int max_id = (int)cmd.Parameters["@PAR"].Value;

myConnection.Close();

//--------------------------------------------------------------------------

----------------------------------------------------------------------------

----

This gives me an error -> "error in SQL-Syntax".

I read the issue with use of "?" instead of "@", and I've tried it all..!, it keeps throwing exeptions like "null values"

"Object reference not set to an instance of an object". and so on.

Anyone have a fail-proof method of creating a command with return-parameters??

Thanks.

Reg.