Vibol Vibol - 1 year ago 112
MySQL Question

Mysqlcommand.ExecuteReaderAsync handle stored procedure that can return one or more result sets

I have a stored procedure that could return 2 sets of results if there were no errors.

The first set is just a normal


The second set contains the error code and error message, this set will always return one row. Since there was no error, the error code will be 0 and error message will be null.


1 set of results if an error has occurred. This set only contain the error code and error message, and will always have one row.

Now in C#, when I call this stored procedure like this:

var aCommand = new MySqlCommand();
aCommand.CommandText = "my_stored_proc";
aCommand.CommandType = CommandType.StoredProcedure;

aCommand.Parameters.Add("@ErrorCode", MySqlDbType.VarChar);
aCommand.Parameters["@ErrorCode"].Direction = ParameterDirection.Output;
aCommand.Parameters.Add("@ErrorMessage", MySqlDbType.VarChar);
aCommand.Parameters["@ErrorMessage"].Direction = ParameterDirection.Output;

var aReader = await aCommand.ExecuteReaderAsync().ConfigureAwait(false);

only contains the first set of the results that are returned by the stored procedure.

My question is how do I get the other set?

Answer Source
aReader.NextResult(); // returns true if there is another result set
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download