0

I am trying to run this simple Dapper example from the test suite in Mysql 5.6.10 (AWS Aurora).

var p = new DynamicParameters(new { a = 1, b = 2 });
p.Add("c", dbType: DbType.Int32, direction:ParameterDirection.Output);
cnn.Execute(@"set @c = @a + @b", p);
var results = p.Get<int>("@c");

However, an exception is being thrown. The @c is being interpreted as NULL> enter image description here

I would like to use two output parameters to return the number of rows affected by an insert statement and the last inserted ID.

3
  • Reproduced on connector 6.9.5 and Dapper 1.42. (and local MySql 5.6.14) Commented Apr 24, 2016 at 7:08
  • 1
    Definitively the problem is not in Dapper itself. That syntax _set @c = @a + @b" is invalid for MySql also in a standard (non Dapper) query. Commented Apr 24, 2016 at 12:08
  • 1
    As @Steve notes: if it isn't valid syntax for your flavor of database server, it just isn't going to work. Dapper makes things more convenient, but it doesn't change what the server supports. Commented Apr 24, 2016 at 14:35

1 Answer 1

1

I found it seems impossible to fetch out parameter from mysql with dapper, so I modified you code a bit to achieve the result.

var p = new DynamicParameters(new { a = 1, b = 2 });
//p.Add("c", dbType: DbType.Int32, direction: ParameterDirection.Output);
//conn.Execute(@"set @c = @a + @b", p);
using (var reader = conn.ExecuteReader(@"set @c = @a + @b; select @c;", p))
{
    //var results = p.Get<int>("@c");
    if (reader.Read())
    {
        var result = reader.GetInt32(0);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.