【发布时间】:2020-10-05 20:52:32
【问题描述】:
从对我的问题 here 的回答或评论中,我得到了 here 的指示。
所以我改变了我的代码:
double _imdbThreshold = 0.0;
(IMDBRating is a Decimal(2,1) data type in the SQL Server (Express) Database.)
...
cmd.Parameters.AddWithValue("@IMDBMinRating", _imdbThreshold);
...到这个:
cmd.Parameters.Add("@IMDBMinRating", SqlDbType.Decimal, 2, 1).Value = _imdbThreshold;
...基于上面链接的文章中的这个例子:
cmd.Parameters.Add("@Parameter", SqlDbType.Decimal, 11, 4).Value = MyDecimalVariable;
但我得到,“无法从 int 转换为字符串”:
?!?
为什么我的“1” int arg 在那里找错了?
【问题讨论】:
-
没有过载
(String, SqlDbType, Int32, Int32),根据documentation。您需要设置精度和比例separately。 -
是的,所以引用的文章是错误的。我想知道它在编写时是否有效,或者没有人测试过。
-
^^ Dirks 的评论准确地提到了那个方法是不正确的。
标签: sql-server int32 commandparameter