Overflow exception when reading decimal values from SQL Server

会有一股神秘感。 提交于 2019-12-05 02:06:46

Its not somthing you are doing wrong, apart from being overly precise perhaps. I don't think its a new problem either.

You could argue its a bug, or just a gap in functionality. The .Net Decimal structure just can't represent the value that is stored in your SQL Server decimal so an OverflowException is thrown.

Either you need to manipulate the value to something compatible in the database before you retrieve it or, read the data out in a raw binary or string format and manipulate on the .Net side.

Alternatively, you could write a new type that handles it.

It's probably simpler just to use a compatible decimal definition in the first place, unless you really need that precision. If you do I'd be interested to know why.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!