I am trying to get the MySQL query text that was generated with the parameters, but so far I have not succeeded.
string query = $"UPDATE table_inputs SET amount = @amount WHERE id = @id";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
command.CommandType = CommandType.Text;
command.Prepare();
command.Parameters.AddWithValue("@id", user_id);
command.Parameters.AddWithValue("@amount", user_amount);
var result = command.ExecuteScalar();
// always 'result' equal NULL
}
The request text is required for logging. I plan to write logs from a multi-threaded application where each operation should have its own unique parameters. Consequently, queries with parameters are needed where it was clear what query and with what parameters was performed. Please tell me what I'm doing wrong and how to do it right.