-2
Good morning, I’m doing an update in a float field on sql server, but I’m not getting this from a conversion error, I tried several ways and did not succeed, I keep getting this error return = Error Converting data type varchar to float.
follows my code.
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update tbl_Produto set Lote = '" + cb_lote.Text + "', Qtda = CONVERT(FLOAT, '" + txt_qtda.Text + "') where Cod_Produto = '" + txt_codigo.Text + "'";
cmd.Connection = conex1;
conex1.Open();
cmd.ExecuteNonQuery();
conex1.Close();
Where is making such a mistake ?
– Dev
am receiving this error Error Converting data type varchar to float. when I update this field Qtda = CONVERT(FLOAT, '" + txt_qtda.Text + "') in my query. The error appears in the grinding of the execution of the cmd.Executenonquery query();
– Junior Guerreiro
Are you sure that usurá
float
for this? https://answall.com/a/38140/101 And if the user enters something wrong, the application breaks?– Maniero
Good is probably here Qtda = CONVERT(FLOAT, '" + txt_qtda.Text + "')
– Dev
what has in
txt_qtda.Text
? Maybe the problem is formatting:select CONVERT(float, '0.123')
works. (checks if the value is not comma)– rLinhares
But a quantity field in kg then has to be this way.
– Junior Guerreiro
txt_qtda.Text values me Kilograms. Ex. 0,200 or 0,05 values like this
– Junior Guerreiro
That’s right the value and put comma in the field.
– Junior Guerreiro
I used a replace to replace the comma by point and it worked, but the amount that was supposed to be 0,200 he recorded 200 in the bank.
– Junior Guerreiro
in this sql Injection code
– Bruno H.
Okay problem solved was putting the comma. I switched for point and it worked, recorded it right, at the time of entering the value, I typed with point and he recorded it right in the bank. .kkk. But thank you very much for all your attention.
– Junior Guerreiro
Working is different than being right.
– Maniero
So I agree yes, now I just need to make the field only accept point and not accept comma, how can I do that?
– Junior Guerreiro