Я использую MySQL, Connector.
using (MySqlConnection connection = new MySqlConnection("..."))
{
connection.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "FN_NEW";
command.Parameters.AddWithValue("P_SESSION_ID", sessionId);
command.Parameters.AddWithValue("P_NAME", deckName);
object result = command.ExecuteScalar(); // returns NULL !!!!!!!!!
return Json(result);
}
По какой-то причине возвращаемое значение равно нулю. Я использую правильный CommandType?
Как я могу вызвать функцию MySQL из .NET?
Окончательная рабочая версия:
using (MySqlConnection connection = new MySqlConnection(GetConnectionString().ConnectionString))
{
connection.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "FN_NEW";
command.Parameters.AddWithValue("P_SESSION_ID", sessionId);
command.Parameters.AddWithValue("P_NAME", deckName);
MySqlParameter returnParam = command.Parameters.Add("@RETURN_VALUE", MySqlDbType.Int32);
returnParam.Direction = System.Data.ParameterDirection.ReturnValue;
command.ExecuteNonQuery();
NewDeckReturnCode result = (NewDeckReturnCode)returnParam.Value;
return Json(result);
}