Dapper.Net SQL批量插入小数精度
Dapper.Net SQL bulk insert decimal precision
我收到来自 Dapper Bulk Copy
的异常
看起来底层的批量复制操作失败了。我将数据转储到 json 中,发现价值创造问题是 259815703.3430760631
StackTrace:
at System.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed)
.....
Inner Exception 1:
InvalidOperationException: The given value of type Decimal from the data source
cannot be converted to type decimal of the specified target column.
Inner Exception 2:
ArgumentException: Parameter value '259815703.34307606' is out of range
table 有 decimal(18,6)
并且 API 没有以较低的精度存储。
我尝试了以下方法并且有效,存储的值是小数点后 6 位而不是预期的 10 位
CREATE TABLE #t1(c1 DECIMAL(18,6))
INSERT INTO #t1(c1) values(259815703.3430760631)
我用 decimal.Round 解决了小数点后 6 位的问题
我收到来自 Dapper Bulk Copy
的异常
看起来底层的批量复制操作失败了。我将数据转储到 json 中,发现价值创造问题是 259815703.3430760631
StackTrace:
at System.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed)
.....
Inner Exception 1:
InvalidOperationException: The given value of type Decimal from the data source
cannot be converted to type decimal of the specified target column.
Inner Exception 2:
ArgumentException: Parameter value '259815703.34307606' is out of range
table 有 decimal(18,6)
并且 API 没有以较低的精度存储。
我尝试了以下方法并且有效,存储的值是小数点后 6 位而不是预期的 10 位
CREATE TABLE #t1(c1 DECIMAL(18,6))
INSERT INTO #t1(c1) values(259815703.3430760631)
我用 decimal.Round 解决了小数点后 6 位的问题