Write float field in sql server with C #

-2

I'm trying to do this, but I'm not sure how to do this, but I'm not sure how to do this. to float.

Follow 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();
    
asked by anonymous 12.09.2017 / 15:24

1 answer

0

Try to pass by parameter, something like this:

string sqlQuery = "update tbl_Produto set Lote=@lote, Qtda=@qtda where Cod_Produto=@codigo";

SqlCommand cmd = new SqlCommand(sqlQuery, conex1);

cmd.Parameters.AddWithValue("@lote", txt_qtda.Text);

cmd.Parameters.Add("@qtda", SqlDbType.Float);
cmd.Parameters["@qtda"].Value = (float) Convert.ToDouble(cb_lote.Text);

cmd.Parameters.Add("@codigo", SqlDbType.Int);
cmd.Parameters["@codigo"].Value = int.Parse(cb_lote.Text);

conex1.Open();
Int32 linhasResultado = cmd.ExecuteNonQuery();
    
12.09.2017 / 15:58