0
I’m having trouble inserting into the database the field is formatted as DECIMAL(10,2)
), when I try to insert the direct monetary value by Mysql works with the endpoint instead of the comma ex:
135.45 - The bank intends the two decimal places.
Now when I try to insert by my program, it records in the flock as follows:
13545.00
Follow my model.Cs for this field
class Modelo
{
private float nValor;
public float Valor
{
get { return nValor; }
set { nValor = value; }
}
}
The action of the button to record the entered value is like this:
private void btn_cadastrar_Click(object sender, EventArgs e)
{
Modelo mo = new Modelo();
conexao con = new conexao();
try
{
if (cbox_pagamento.SelectedItem.ToString() == "a vista")
{
mo.Data_Compra = txt_dcompra.Text;
mo.Data_Alvo = txt_dalvo.Text;
mo.Fornecedor = txt_fornecedor.Text;
mo.Valor = float.Parse(txt_valor.Text);
mo.Tipo = cbox_tipo.Text;
mo.Pagamento = lbl_fiado.Text;
mo.Data_Pagamento = txt_dpagamento.Text;
con.cadastro(mo);
txt_fornecedor.Text = "";
txt_valor.Text = "";
MessageBox.Show("Dados gravados com sucesso!");
}
else
{
mo.Data_Compra = txt_dcompra.Text;
mo.Data_Alvo = txt_dalvo.Text;
mo.Fornecedor = txt_fornecedor.Text;
mo.Valor = float.Parse(txt_valor.Text);
mo.Tipo = cbox_tipo.Text;
mo.Pagamento = lbl_fiado.Text;
mo.Data_Pagamento = txt_dpagamento.Text;
con.cadastro_aprazo(mo);
txt_fornecedor.Text = "";
txt_valor.Text = "";
MessageBox.Show("Dados gravados com sucesso!");
}
}
catch (Exception ex)
{
MessageBox.Show("Falha ao salvar no banco de dados :" + ex);
}
}
Does anyone have any idea how I put the value in the bank correctly?
I did as you proposed but the problem occurred in the same way, When I inform the value in the system 135,15 or 135.15 he inserts in the bank 13515.00 do not know the reason. you know how I can try to fix this ?
– Bruno Felipe Kouuds
So you need to give more details of how your code is, how the data is. Starting by telling you what the problem is. Maybe it’s s[the case of dividing by 100.
– Maniero
I will publish my entire code to have a look, https://pastebin.com/3CV5pK3Q - Purchase Form https://pastebin.com/tpPgT06t - Project Template https://pastebin.com/tABv1Xe - Project Connection
– Bruno Felipe Kouuds
Then I try to take a look, but this code is all full of repetitions and other weird things. If I were you I would try to learn the basics before trying to do something sophisticated.
– Maniero
I try to learn by doing in practice, taking tips and applying, seeing tutorials and etc. However I am very sorry
– Bruno Felipe Kouuds
But it seems to be on the wrong track, there’s a huge amount of problems in that code. Usually going aimlessly like this doesn’t usually work out, I don’t know anyone who’s learned to program like this. You have to do it in a structured way, maybe with accompaniment of those who understand the subject. What is more on the Internet is people who do not know teaching wrong.
– Maniero
You have someone who can tell me that you have a web page or even a youtube page ?
– Bruno Felipe Kouuds
These codes there are of a control of accounts to pay everything is working perfectly the only problem I discovered was that of the value, but I understand you must have a lot of unnecessary and repeated thing more it is practical
– Bruno Felipe Kouuds
There is a big difference between working and being right. I wouldn’t call it perfectly. You can tell by the code that there are several errors. There are problems of validation and data entry, there are calculations that will generate rounding errors, there is wrong treatment of exception, repetition and other things that I could not even understand why it is there, only what I remember. But if you who are starting think that everything is perfect and the wrong is I who have 35 years of experience, then I can not help much.
– Maniero
I’m not saying at any point that you’re wrong, I just came to the forum to get help for a problem and can’t stand that I’m demotivating, I’m going to keep studying and I’m going to review the teaching methods better. But I wanted to know why it’s not working, why I haven’t figured it out yet. Anyway you’ve helped me.
– Bruno Felipe Kouuds
I’m motivating you to do the right thing, and if you choose the wrong way, you’ll be discouraged when you realize that everything is falling apart and it’s not the way you were thinking. If you give me time I’ll see more.
– Maniero
All right, buddy, I’ve unfortunately been doing everything I can to find out, and I just couldn’t solve it. but no hurry when you have a little time and can take a look I would really appreciate it.
– Bruno Felipe Kouuds
Print the entered value before converting or saving to the bank.
– Maniero
I’m sorry for the ignorance but I don’t understand.
– Bruno Felipe Kouuds