OUTPUT Parameters in Stored Procedure

OUTPUT Parameters in Stored Procedure

Postby pvl » Wed 02 Nov 2005 20:46

Hi, I have this SP:
------------
CREATE PROCEDURE `z1`(param1 INTEGER(11), OUT param2 INTEGER(11))
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT ''
BEGIN
set param2=param1*2;
END;
-------------
when I try run ExecuteNonQuery() method I get error msg: "OUT or INOUT argument 2 for routine z1 is not a variable".
How I can get value from OUT parameters?

Thanks.
pvl
 
Posts: 12
Joined: Fri 14 Oct 2005 07:53

Postby Serious » Thu 03 Nov 2005 12:23

To receive out parameters from stored procedures you have to use following syntax
Code: Select all
MySqlCommand command = new MySqlCommand("call z1(10, @param2);select @param2;", connection);
using (IDataReader reader = command.ExecuteReader())
{
  if (reader.Read())
    Console.WriteLine("@param2 = " + reader[0]);
}
Serious
 


Return to dotConnect for MySQL