I'm trying to insert some values to mysql database via C#
INSERT INTO cliente (column1, column2) VALUES (value1, value2);
set @ultima_pk =  LAST_INSERT_ID();
INSERT INTO cliente_ref (refCol1, refCol2) VALUES (refvalue1, (SELECT @ultima_pk));
INSERT INTO cliente_ref (refCol1, refCol2) VALUES (refvalue1, (SELECT @ultima_pk));
When I test it in mysql only, work perfectly but when I try to insert it via C# I cannot.
Error message:
Parameter '@ultima_pk' must be defined.
But @ultima_pk not is param, is a mysql variable.
Bellow the insert function
public bool insert(string query)
{
    this.conectar();
    cmd = new MySqlCommand(query, this.conexion);
    cmd.ExecuteReader();
    //bool retornar = cmd.ExecuteNonQuery() >= 1 ? true : false;
    bool retornar = true;
    this.desconectar();
    return retornar;
}
The connection is working perfecfly.
Any suggestion How can I pass @ultima_pk inside of query in C#?
                        
You need to declare it, and then you don't need to select it:
Call it like this: