Inserting value of type double in the mysql database

0

I have a WindowsForm with a value field and I need to enter the value of it in the database.

Do I need some examples of how to do this?

Query file

//Cadastrar Gastos
        public void cadastroGasto(Gasto gasto)
        {
            try
            {
                string inserir = "INSERT INTO gasto(descricao,valor,funcionario_id)value('"+ gasto.Descricao +"', '"+ gasto.Valor +"', '"+ gasto.Funcionario_id +"')";

                conexao = new MySqlConnection(caminho);
                MySqlCommand comandos = new MySqlCommand(inserir, conexao);

                conexao.Open();
                comandos.ExecuteNonQuery();
                conexao.Close();
            }

            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                MessageBox.Show("Cadastro efetuado com sucesso!",
                    "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conexao.Close();
            }
        }

Here is the code for windowsForm

private void btnSalvar_Click(object sender, EventArgs e)
        {
            Classes.Gasto gasto = new Classes.Gasto();

            Classes.DBconect con = new Classes.DBconect();

            gasto.Descricao = txtDescricao.Text;
            string valor = txtValor.Text;
            Decimal dvalor = Convert.ToDecimal(valor, System.Globalization.CultureInfo.GetCultureInfo("pt-BR"));

            gasto.Valor = dvalor;

            gasto.Funcionario_id = int.Parse(cmbFuncionario.SelectedValue.ToString());

            this.ValidarCampos();

            //verifica se as validações retornaram true
            if (this.ValidarCampos() == true)
            {
                //Insere os dados no bd
                con.cadastroGasto(gasto);
             }
      }

This second block of code is not working to insert txtValue

    
asked by anonymous 08.01.2015 / 01:25

0 answers