Vibol Vibol - 2 months ago 13
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

select
.

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.

and

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);


aReader
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
aReader.NextResult(); // returns true if there is another result set