c# - Convert.ToDouble() 因 SqlDataReader 值溢出

标签 c# sqldatareader

Convert.ToDouble(rdr["value"]) 

当 SQL Server 中显示的值为 75875563.7000000000000000000000 时,引发“转换溢出”错误。

enter image description here

堆栈跟踪:

   at System.Data.SqlClient.SqlBuffer.get_Decimal()
   at System.Data.SqlClient.SqlBuffer.get_Value()
   at System.Data.SqlClient.SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData)
   at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
   at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
   at System.Data.SqlClient.SqlDataReader.get_Item(String name)
   at DataAPI.Models.Title.TitleDB.getTitlePerformance(Nullable`1 StartDate, Nullable`1 EndDate) in c:\00 BI Source\BIPortal\DataAPI\DataAPI\Models\Title\TitleDB.cs:line 44

有人可以告诉我这是为什么吗?

最佳答案

这是关于十进制容量的。你可以在sql server端使用十进制(16,4)(或者你需要的一些精度)吗?十进制 (16,4) 表示 16 个字符,后面 4 位数字,

关于c# - Convert.ToDouble() 因 SqlDataReader 值溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23941401/

相关文章:

c# - 如何使用 C# 向 facebook 收件箱发送消息?

c# - Xamarin iOS 中无参数的绑定(bind)方法

c# - 长类名会影响 XAP 文件的大小吗?

c# - 将 Lookup<TKey, TElement> 转换为其他数据结构 c#

从 SqlDataReader 返回 Nullable 类型的 C# 性能提升

c# - 从数据库读取 bool 值?

c# - SQLDataReader 抛出异常失败

c# - 为什么我不应该写 list.Count.Equals(0)

sql - ExecuteReader 需要一个打开且可用的连接。连接的当前状态是关闭的

sql-server - 检查 SQL MAX() 函数返回 null