SQLCommand.Parameters.Add-如何给出十进制值的大小? [英] SQLCommand.Parameters.Add - How to give decimal value size?
本文介绍了SQLCommand.Parameters.Add-如何给出十进制值的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您将如何指定呢?
Decimal(18,2)
在此:
SqlComm.Parameters.Add("@myValue", SqlDbType.Decimal, 0, "myValue");
目前,我已经从设计方面的属性中定义了 precision = 2
.我只是好奇如何从代码中完成此操作.谢谢
Currently I have defined precision = 2
from the design side properties. I'm just curious as to how to accomplish this from the code. Thanks
推荐答案
没有 Add
的重载,它允许您设置小数精度内联,因此您要么需要创建SQlParameter对象并添加到收藏夹中:
There's not an overload of Add
that lets you set the decimal precision inline, so you either need to create a SQlParameter object and add it to the collection:
SqlParameter param = new SqlParameter("@myValue", SqlDbType.Decimal);
param.SourceColumn = "myValue";
param.Precision = 18;
param.Scale = 2;
SqlComm.Parameters.Add(param);
或查找"添加后的参数:
or "find" the parameter after adding it:
SqlComm.Parameters.Add("@myValue", SqlDbType.Decimal, 0, "myValue");
SqlParameter param = SqlComm.Parameters["@myValue"];
param.Precision = 18;
param.Scale = 2;
或使用参数构造函数:
SqlComm.Parameters.Add(new SqlParameter(
parameterName = "@myValue",
dbType = SqlDbType.Decimal,
precision = 18,
scale = 2,
sourceColumn = "myValue"));
这篇关于SQLCommand.Parameters.Add-如何给出十进制值的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文