I'm trying to extract value from output parameter in SQL procedure but I kept getting this exception
OUT or INOUT argument 2 for routine insertItem is not a variable or NEW pseudo-variable in BEFORE trigger
So this is my MySQL procedure
DELIMITER //
CREATE PROCEDURE insertItem(
in $description varchar(200),
out $outItemID int
)
BEGIN
insert into item(
description
)
values(
$description
);
set $outItemID = last_insert_id();
select $outItemID;
END //
DELIMITER ;
the stored procedure works fine when it execute in workbench
call insertItem('any description', @outItemID);
but when it comes to my C# backend service
using (connection){
connection.Open();
query = "call insertItem(@description, @outItemID);";
command = new MySqlCommand(query, connection);
AddParameterValue("@description", request.Item.Description);
command.Parameters.AddWithValue("@outItemID", MySqlDbType.Int32);
command.Parameters["@outItemID"].Direction = System.Data.ParameterDirection.Output;
command.ExecuteNonQuery();
...//extract value from output parameter
}
the MySqlException was caught.
P.S. AddParameterValue functions work completely fine