I have a table column of my bank called salario_base
where it is of type Decimal(7,2)
. I insert the value into a textbox
, convert it and pass this and other variables to an insert class to complete this operation. The other data are being perfectly saved, but the salary is not. Here's an example of what I'm trying to save to the bank:
Ex: 1500.65
I try to perform the insertion shown in the example above, but only the 1500.00 value is saved, when I do not use the " p>
The variable is declared in the application as a variable of the decimal type. Edit. Follow the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Sistema_RH.Classes;
using Sistema_RH.FORMULARIOS;
using Sistema_RH.NEGOCIOS;
namespace Sistema_RH.DADOS
{
public class DAOFolhadePagamento
{
public void CadastrarPayment(string rsocial, string cnpj, string nomefunc, decimal sbase, string depart, string obs)
{
using (MySqlConnection connectaInBD = DAOConexao.getConnection())
try
{
string RazaoSocial = rsocial;
string CNPJ = cnpj;
string NomeFuncionario = nomefunc;
decimal SalarioBase = sbase;
string Departamento = depart;
string Observacoes = obs;
string ComandoSQL = "INSERT INTO folhadepagamento (razao_social, cnpj, nome_do_funcionario, salario_base, departamento, observacoes)" +
" VALUES (@razao_social, @cnpj, @nome_do_funcionario, @salario_base, @departamento, @observacoes)";
System.Windows.Forms.MessageBox.Show(ComandoSQL);
connectaInBD.Open();
MySqlCommand inserttDados = new MySqlCommand(ComandoSQL, connectaInBD);
inserttDados.Parameters.Add("@razao_social", MySqlDbType.VarChar, 100);
inserttDados.Parameters.Add("@cnpj", MySqlDbType.VarChar, 30);
inserttDados.Parameters.Add("@nome_do_funcionario", MySqlDbType.VarChar, 100);
inserttDados.Parameters.Add("@salario_base", MySqlDbType.Decimal, 12);
inserttDados.Parameters.Add("@departamento", MySqlDbType.VarChar, 50);
inserttDados.Parameters.Add("@observacoes", MySqlDbType.VarChar, 500);
inserttDados.Parameters["@razao_social"].Value = RazaoSocial;
inserttDados.Parameters["@cnpj"].Value = CNPJ;
inserttDados.Parameters["@nome_do_funcionario"].Value = NomeFuncionario;
inserttDados.Parameters["@salario_base"].Value = SalarioBase;
inserttDados.Parameters["@departamento"].Value = Departamento;
inserttDados.Parameters["@observacoes"].Value = Observacoes;
inserttDados.ExecuteNonQuery();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
connectaInBD.Close();
}
}
}
}
Edit2: I made the modifications that were suggested to me in the comments. But the amount is still not being stored in the bank the way you wanted it to be (as explained at the beginning). I tried to insulate the textbox
referring to the input of this value and I drew the direct value in the Salario_Base
variable.
Example:
Ex:: decimal SalarioBase = 1500.55M;
esse M was the same Visual Studio that suggested, in this way the insertion occurred and the value was saved as expected in the database.
I thought about using the Concat(txtSalarioBase.Text, "M");
method and then using Convert.ToDecimal();
. But it does not seem to work , so I did not even try implement, I'm following the instructions in the link above. I really do not know what to do ...