vb.net - .NET saving to DB truncates my decimals instead of rounds them.. what could be possible problems? -


i'm not using entity framework, using microsoft enterprise library.

i have value like: 1.125979843654984 gets truncated 1.125, instead of rounded 1.126.

the precision of column value in decimal(5,3).

what reasons happen?

is there other information provide help?

i'm new .net.

update 1

  • add relevant code

the code invokes saving process:

dim dscalcgroupbyband new dataset dscalcgroupbyband.tables.add(dtcalcgroupbyband) dscalcgroupbyband.tables(0).tablename = "table" dal.savegriddataset(dscalcgroupbyband, "select * tblltdcalcgroupbyband igroupky=" & groupdata.groupno, false, false) 

the method method in variable dal:

public function savegriddataset(byval pds dataset, byval psql string, _     optional byval pcheckisnewgroup boolean = true, _     optional byval pforceasnewgroup boolean = false, _     optional byval psqldelete string = "") boolean    dim da new sqldataadapter   dim commandbuilder sqlcommandbuilder   dim adapter sqldataadapter   dim updatedrows integer    using connection sqlconnection = _database.createconnection()      try       if ((pcheckisnewgroup = true) , (groupdata.isnewgroup = true)) or _       (pforceasnewgroup = true)         pds = isnewgroup(pds)       end if       da = new sqldataadapter(psql, connection) '_database.getdataadapter       ' make commandbuilder generate insert, update, , delete commands.       commandbuilder = new sqlcommandbuilder(da)        ' save changes.       da.update(pds)      catch e invalidoperationexception       try         ' it's horrible run code, in here, there need tests         ' implemented before modifying above code.         adapter = new sqldataadapter(psql, connection)         commandbuilder = new sqlcommandbuilder(adapter)         'adapter.selectcommand = commandbuilder.getupdatecommand         updatedrows = adapter.update(pds)       catch ee dbconcurrencyexception         ' there no change (data exists, no need update)         console.writeline("no data written")       end try      catch e dbconcurrencyexception        ' delete current records using optional delete psqldelete       if psqldelete = ""         psqldelete = psql.replace("select *", "delete")       end if       updatesql(psqldelete)        ' create dataset if new group , try update again       da.update(isnewgroup(pds))     catch e exception        console.writeline("un-mitigated exception")       console.writeline(e.message)     end try     end using   end function 
  • disclaimer above code snippets: both came legacy code.

using above decimals example: in dtcalcgroupbyband datatable, there exists row field of value 1.125979843654984 corresponding column in database of datatype decimal(5,3) -- however, particular corresponding datacolumn object of datatype system.decimal - problem coming from? perhaps?

anyway, once saved, (after calling dal.savegriddataset(...)), value in table, , shows 1.125 (truncated) instead of 1.126 (rounded)

update 2

using microsoft enterprise library (or other oo way of accessing database), how retrieve column's precision?

the column declared decimal(5,3), 3 places of precision right of decimal value, rest truncated.

if want round value, have round in datatable column before saving database, or in sql statement being executed.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -