Cannot insert decimal table into sql server via C # code

I cannot insert decimal values ​​into the Sql server table.

What I'm trying to do explains itself through these lines of code:

long fileSizeInBytes = ComponentUploadControl.FileContent.Length;
Decimal fileSizeInMB = Convert.ToDecimal(fileSizeInBytes) / (1024.0m * 1024.0m);
Decimal fileSizeInMBRounded = Math.Round(fileSizeInMB, 2);
cmd.Parameters.Add("@fileSize", SqlDbType.Decimal).Value = fileSizeInMBRounded;

The value inserted into the database is not decimal. To be more specific, if fileSizeInMBRounded is 11.73, the value that gets into the database is 11.00

Please help me

Thanks pending

+5
source share
4 answers

, SQL. , , - decimal(18,2), 2 . , decimal(18,0) ( ), .

SQL Server Profiler INSERT, , , - SQL.

+8

SqlParameter.Scale 2.

SqlParameter parameter = new SqlParameter("@fileSize", SqlDbType.Decimal);
parameter.Scale = 2;
parameter.Value = fileSizeInMBRounded;
cmd.Parameters.Add(parameter);

Precision, Bruno ( 0).

+3

.

, .

+1

.

+1

All Articles