在prepared声明C#中使用SqlDBType.Decimal [英] Using SqlDBType.Decimal in Prepared Statement C#

查看:103
本文介绍了在prepared声明C#中使用SqlDBType.Decimal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在使用C#中的prepared声明。

am using a Prepared Statement in C#.

 SqlCommand inscommand = new SqlCommand(supInsert, connection);
 inscommand.Parameters.Add("@ordQty", SqlDbType.Decimal,18);
 inscommand.Prepare();
 u = inscommand.ExecuteNonQuery();

以上code以下抛出异常:

The above code throws below Exception:

的SqlCommand。prepare方法需要类型的十进制参数有一个明确设置precision和缩放。

编辑:如何避免这种异常

How to avoid this Exception

推荐答案

下面将设定precision一个小数18,SCAL 8(十进制(18,8))

The following would set a Decimal with Precision 18 and Scal 8 (Decimal (18,8))

SqlCommand inscommand = new SqlCommand(supInsert, connection);
inscommand.Parameters.Add("@ordQty", SqlDbType.Decimal,18);

inscommand.Parameters["@ordQty"].Precision = 18
inscommand.Parameters["@ordQty"].Scale = 8

inscommand.Prepare();
u = inscommand.ExecuteNonQuery();

这篇关于在prepared声明C#中使用SqlDBType.Decimal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆