List:MySQL and .NET« Previous MessageNext Message »
From:Reggie Burnett Date:September 26 2004 7:08am
Subject:RE: Return parameter from query.
View as plain text  
Out, intout, and return parameters are only supported when dealing with
stored procedures in 5.0 and later.  For what you are doing, you should
not use a parameter.  See this code.

MySqlCommmand cmd = new MySqlCommand("SELECT MAX(ID) FROM myTable",
conn);
Object max = cmd.ExecuteScalar();

HTH,
Reggie

-----Original Message-----
From: Asbjørn Konstad [mailto:asbjorn@stripped] 
Sent: Friday, September 24, 2004 3:06 AM
To: dotnet@stripped
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.

 

Asbjørn Konstad


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22.09.2004
 

Thread
Return parameter from query.Asbjørn Konstad24 Sep
  • Re: Return parameter from query.Fredrick Bartlett26 Sep
  • RE: Return parameter from query.Reggie Burnett26 Sep
    • Better way to get all columns in the DataReaderGuy Platt6 Oct
      • RE: Better way to get all columns in the DataReaderJordan Sparks6 Oct
        • Re: Better way to get all columns in the DataReaderGuy Platt6 Oct
          • RE: Better way to get all columns in the DataReaderJordan Sparks6 Oct
          • Re: Better way to get all columns in the DataReaderBarry Zubel6 Oct
    • Re: Better way to get all columns in the DataReaderFredrick Bartlett6 Oct