How to insert float value by arraylist - C #?

1

Hello, I can not pass a floating value (price) by arraylist to the bank. I wonder if I need to convert before passing or if there is any way to do it straight. I already searched the Stack here, but I did not find anything like it. Here is the code I am studying:

public bool Insert(ArrayList p_arrInsert)

  {  

vsql = "INSERT INTO tb_produtos ([PROD_NOME],[PROD_TIPO],PROD_DESCRICAO],[PROD_PRECO]) VALUES (@PROD_NOME, @PROD_TIPO, @PROD_DESCRICAO, @PROD_PRECO)";

            SqlCommand objcmd = null;


            if (this.conectar())
            {

                try
                {
                    objcmd = new SqlCommand(vsql, objCon);
                    objcmd.Parameters.Add(new SqlParameter("@PROD_NOME", p_arrInsert[0]));
                    objcmd.Parameters.Add(new SqlParameter("@PROD_TIPO", p_arrInsert[1]));
                    objcmd.Parameters.Add(new SqlParameter("@PROD_DESCRICAO", p_arrInsert[2]));
                    objcmd.Parameters.Add(new SqlParameter("@PROD_PRECO", p_arrInsert[3]));

                    objcmd.ExecuteNonQuery();

                    return true;

                }
                catch (SqlException sqlerr)
                {
                    throw sqlerr;
                }
                finally
                {
                    this.desconectar();
                }
            }
            else
            {
                return false;
            }
        }

I get the data through a button:

 private void btnCadastrar_Click(object sender, EventArgs e)
        {
            sisDBADM_PRODUTOS obj = new sisDBADM_PRODUTOS();
            ArrayList arr = new ArrayList();
            try
            {
                arr.Add(tbCad_nome.Text);
                arr.Add(cbTipo.Text);
                arr.Add(tbCad_nome.Text);
                arr.Add(tbCad_descricao.Text);
                arr.Add(tbCad_preco.Text);

                if (obj.Insert(arr))
                {
                    MessageBox.Show("Produto cadastrado com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    tbCad_codigo.Text = "";
                    tbCad_nome.Text = "";
                    tbCad_descricao.Text = "";
                    tbCad_preco.Text = "";


                    dgProdutos.DataSource = obj.ListaGrid(); //recarrega o datagrid

                }
                else
                {
                    MessageBox.Show("Erro ao cadastrar o produto", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro + "Erro Ocorrido!");

            }
        }

I get the error: Error converting nvarchar data type to float ....

    
asked by anonymous 31.01.2017 / 15:12

1 answer

0

I am working with access and saved the decimal values in a column in text (Examples: 21275 | 47404,95 | 66295,9), I make the treatment for display through string.Format and to manipulate in the system I use a property of type decimal?.

Another thing you can do is to change how popular the parameters:

cmd.Parameters.Add("@StatusId", OleDbType.Integer).Value = ((object)pendencia.StatusId) ?? DBNull.Value;
cmd.Parameters.Add("@FollowUp", OleDbType.Date).Value = (String.IsNullOrEmpty(pendencia.FollowUp) ? DBNull.Value : (((object)pendencia.FollowUp) ?? DBNull.Value));
cmd.Parameters.Add("@DocumentoTipo", OleDbType.VarChar, 255).Value = ((object)pendencia.DocumentoTipo) ?? DBNull.Value;
cmd.Parameters.Add("@IsCritico", OleDbType.Boolean).Value = ((object)pendencia.IsCritico) ?? DBNull.Value;
    
31.01.2017 / 19:19