Ghilo
Ghilo

Reputation: 3

How to call an Output Parameter from a Mysql stored procedure in ASP.NET

I am having a problem returning an output parameter from a Mysql stored procedure into a ASP.NET Variable. I just want the ligne code to use in ASP to get that Parameter ! Thank you

Upvotes: 0

Views: 1401

Answers (1)

akg179
akg179

Reputation: 1559

let's suppose that there is a parameter named 'MyOutParam' which is an output type of parameter for your MySQL stored procedure. In that case what you will have to do is:

// here goes the logic of instantiating the command for a stored procedure

// cmd is the reference variable containing instance of SQLCommand
cmd.Parameters.Add(new MySqlParameter(“MyOutParam”, MySqlDbType.VarChar));
cmd.Parameters[“MyOutParam”].Direction = ParameterDirection.Output;         // this is how we declare the parameter to be of 'output' type.

cmd.ExecuteNonQuery();

// this is how we can get the value in the output parameter after stored proc has executed
var outParamValue = cmd.Parameters[“MyOutParam”].Value;

Upvotes: 1

Related Questions