【发布时间】:2021-07-20 18:25:19
【问题描述】:
我正在尝试将 JObject 字符串值保存为小数,然后插入 SQL 数据库。
insertWellData.Parameters.Add("@Latitude", SqlDbType.Decimal).Value = entityParams["Latitude"].ToObject<decimal>();
纬度值为空或字符串,即 49.4567 我在这上面有一个 if 语句来整理空值,所以我知道它们不是问题。
if (entityParams["Longitude"].Type == JTokenType.Null)
当我运行我的代码时,我立即得到错误
System.FormatException: 'Input string was not in a correct format.'
这是由于在代码运行开始时未定义纬度值引起的,还是我缺少其他东西?
【问题讨论】:
-
那么是
ToObject<decimal>代码失败了吗?如果是这样,ADO.NET 部分就不那么相关了。如果您可以提供minimal reproducible example 以便我们自己测试,这将有所帮助。