Error passing decimal data

1

I have problems passing decimal records to sql from c #. Passes well the fields type int , date , bit , but decimals passes them in 0 (0.00).

This is part of the transfer code:

while (ReaderMov.Read())
{   
    command.Parameters.Clear();

    command.Parameters.AddWithValue("@asie", ReaderMov[0].ToString());
    command.Parameters.AddWithValue("@fech", ReaderMov[1].ToString());
    command.Parameters.AddWithValue("@cod", ReaderMov[2].ToString());
    command.Parameters.AddWithValue("@conc", ReaderMov[3].ToString());
    command.Parameters.AddWithValue("@cuen", ReaderMov[4].ToString());
    command.Parameters.AddWithValue("@desc", ReaderMov[5].ToString());

    decimal NumDeb = Convert.ToDecimal("@debi");
    decimal.TryParse("@debi", out NumDeb);
    command.Parameters.AddWithValue("@debi", NumDeb.ToString());

    decimal NumCre = Convert.ToDecimal("@cred");
    decimal.TryParse("@cred", out NumCre);
    command.Parameters.AddWithValue("@cred", NumCre.ToString());

    command.Parameters.AddWithValue("@nroc", ReaderMov[8].ToString());
    command.Parameters.AddWithValue("@deta", ReaderMov[9].ToString());
    command.Parameters.AddWithValue("@hoja", ReaderMov[10].ToString());
    command.Parameters.AddWithValue("@reng", ReaderMov[11].ToString());
    command.Parameters.AddWithValue("@vari", ReaderMov[12].ToString());
    command.Parameters.AddWithValue("@pase", ReaderMov[13].ToString());
    command.Parameters.AddWithValue("@ptov", ReaderMov[14].ToString());
    command.Parameters.AddWithValue("@tipo", ReaderMov[15].ToString());
    command.Parameters.AddWithValue("@fein", ReaderMov[16].ToString());
    command.Parameters.AddWithValue("@fefi", ReaderMov[17].ToString());
    command.Parameters.AddWithValue("@fevt", ReaderMov[18].ToString());
    command.Parameters.AddWithValue("@usua", ReaderMov[19].ToString());
    command.Parameters.AddWithValue("@maqu", ReaderMov[20].ToString());

    command.ExecuteNonQuery();
}
    
asked by Jorge Campos 05.09.2017 в 19:02
source

1 answer

1

The format with which you send the information is not correct. For example, the statement decimal NumDeb = Convert.ToDecimal("@debi"); will try to convert @debi to decimal, which will cause an error.

If what you try to send the value of reader changes the decimal parameters for the following:

decimal NumDeb = Convert.ToDecimal(ReaderMov[6].ToString());
command.Parameters.AddWithValue("@debi", NumDeb.ToString());

decimal NumCre = Convert.ToDecimal(ReaderMov[7].ToString());
command.Parameters.AddWithValue("@cred", NumCre.ToString());
    
answered by 05.09.2017 в 19:33