Insert decimal variable in Firebird

Asked

Viewed 406 times

0

I am making an Insert in Firebird database in a Value field (decimal), but no decimals appear in the table.

Code in C# :

public decimal ValorUnitario { get; set; }

produto.ValorUnitario = Convert.ToDecimal(5.50);
string sql = $"INSERT INTO PRODUTO(VALOR_UNITARIO)VALUES('{produto.ValorUnitario}');

In the database you enter Value = 55

3 answers

1

The problem was solved by making a change in the table structure, before my VALOR_UNITARIO field was a decimal (18.0) and I made a change changing the field structure to decimal(18,2).

ALTER TABLE PRODUTO ALTER COLUMN VALOR_UNITARIO TYPE DECIMAL(18,2); – @Edison 

0


The problem is not fully clarified in the question because there is no structure of the tables involved.

More information about Firebird numerical data types can be accessed at: Fixed-Point Data Types

Create a test table with the following DDL:

CREATE TABLE TESTE (
ID     INTEGER NOT NULL,
NOME   VARCHAR(40) NOT NULL,
VALOR  DECIMAL(15,2));

Insert a record with the command:

insert into teste(id, nome, valor) values(101,'teste', 4.52);
commit;

In test performed, with the commands executed by the ibexpert the result was expected.

0

Not working with C# but is using product.Valuario to convert the value and entity.Valuario to concatenate the SQL String. If this is correct, ok, but check the contents of the SQL variable, which contains the command to be executed, maybe there will already find the problem. For Firebird the decimal format must be separated by "." ie 5.5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.