How to get an output parameter from MySql via C #

1

I researched and applied what I saw, but it is giving error:

MySqlConnection con = new MySqlConnection(banco.Conexao);
MySqlCommand comando = new MySqlCommand("sp_venda", con);
comando.CommandType = System.Data.CommandType.StoredProcedure;

comando.Parameters.Add("usuario", MySqlDbType.Int32).Value = banco.Usuario;
comando.Parameters.Add("dinheiro", MySqlDbType.Double).Value = banco.formataDinheiro(Venda.Dinheiro);
comando.Parameters.Add("debito", MySqlDbType.Double).Value = banco.formataDinheiro(Venda.Dinheiro);
comando.Parameters.Add("credito", MySqlDbType.Double).Value = banco.formataDinheiro(Venda.Dinheiro);
comando.Parameters.Add("voucher", MySqlDbType.Double).Value = banco.formataDinheiro(Venda.Dinheiro);
comando.Parameters.Add("desconto", MySqlDbType.Double).Value = banco.formataDinheiro(VendaBLL.somaDescontos().ToString());
comando.Parameters.Add("troco", MySqlDbType.Double).Value = banco.formataDinheiro(Venda.Troco);

MySqlParameter paramHorario = new MySqlParameter("horario", MySqlDbType.Time);
paramHorario.Direction = System.Data.ParameterDirection.Output;

comando.Parameters.Add(paramHorario);

con.Open();
comando.ExecuteNonQuery();
Venda.Horario = comando.Parameters["horario"].Value.ToString();
con.Close();

The error occurs in the following line:

comando.ExecuteNonQuery();

The connection opens normally. The error returned is: "FormatException: Input string was not in an incorrect format." What am I doing wrong?

Edit

 public static string formataDinheiro(string grana)
 {
   if (DetectaTipo(grana) == "null")
      return "null";

 return grana.Replace("R$ ", "").Replace(",", ".");
 }
    
asked by anonymous 26.03.2014 / 16:44

1 answer

1

This means that some of your parameters are not formatted as they should. Its banco.formataDinheiro() function is not returning a Double , but a String . So the error.

To work with money, the ideal is Decimal type. Double can cause complications, such as rounding problems.

    
26.03.2014 / 16:48