将 varchar转换为数据类型 numeric 时出现算术溢出错误。
我用的是.netC#winfrom及Sqlserver代码如下:strings="updateGoodssetgoodsName=N'"+GoodsName+"',goo...
我用的是.net C# winfrom 及Sqlserver
代码如下:
string s = "update Goods set goodsName = N'" + GoodsName + "',goodsCost = '" + GoodsCost + "',goodsSalePrice = '" + GoodsSalePrice + "',";
s = s +"goodsDiscost = '" + GoodsDiscost + "',goodsSupplierId = '" + GoodsSupplier + "',goodsStockQty = " + GoodsQty + ",goodsNote = N'" + GoodsNote + "'";
s = s + " where goodsId = '" + GoodsID + "'";
其中goodsDiscost,goodsCost,goodsSalePrice 在数据库中我定义的都是decimal(6,2)。如果我直接对数据库操作例如:update Goods set goodsCost = '12.50' where gooodsId = 'sok4567' 是没有问题的,但是如果用上述语句操作就不行。就不知道为什么goodsDiscost,goodsCost,goodsSalePrice 怎么赋值都是不对的。
请哪位大侠帮帮忙解解惑。谢谢了!
谢谢那个二楼的不知名人士,的确是这么个问题。
但是请问解决办法是什么啊?? 展开
代码如下:
string s = "update Goods set goodsName = N'" + GoodsName + "',goodsCost = '" + GoodsCost + "',goodsSalePrice = '" + GoodsSalePrice + "',";
s = s +"goodsDiscost = '" + GoodsDiscost + "',goodsSupplierId = '" + GoodsSupplier + "',goodsStockQty = " + GoodsQty + ",goodsNote = N'" + GoodsNote + "'";
s = s + " where goodsId = '" + GoodsID + "'";
其中goodsDiscost,goodsCost,goodsSalePrice 在数据库中我定义的都是decimal(6,2)。如果我直接对数据库操作例如:update Goods set goodsCost = '12.50' where gooodsId = 'sok4567' 是没有问题的,但是如果用上述语句操作就不行。就不知道为什么goodsDiscost,goodsCost,goodsSalePrice 怎么赋值都是不对的。
请哪位大侠帮帮忙解解惑。谢谢了!
谢谢那个二楼的不知名人士,的确是这么个问题。
但是请问解决办法是什么啊?? 展开
2011-04-16
展开全部
我告诉你吧,在你执行这句update Goods set goodsCost = '12.50' where gooodsId = 'sok4567' 语句是,sql系统隐式的将'12.50' 转换成12.50的decimal(6,2)数据类型,但是他不能将字符串“ab”隐式的转换成你所需要的,ok?
展开全部
数字的值不能大于等于10000
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
改成这样试试:
string s = "update Goods set goodsName = N'" + GoodsName + "',goodsCost = convert(varchar,'" + GoodsCost + "',0),goodsSalePrice = convert(varchar,'" + GoodsSalePrice + "',0),";
s = s +"goodsDiscost = convert(varchar,'" + GoodsDiscost + "',0),goodsSupplierId = '" + GoodsSupplier + "',goodsStockQty = " + GoodsQty + ",goodsNote = N'" + GoodsNote + "'";
s = s + " where goodsId = '" + GoodsID + "'";
string s = "update Goods set goodsName = N'" + GoodsName + "',goodsCost = convert(varchar,'" + GoodsCost + "',0),goodsSalePrice = convert(varchar,'" + GoodsSalePrice + "',0),";
s = s +"goodsDiscost = convert(varchar,'" + GoodsDiscost + "',0),goodsSupplierId = '" + GoodsSupplier + "',goodsStockQty = " + GoodsQty + ",goodsNote = N'" + GoodsNote + "'";
s = s + " where goodsId = '" + GoodsID + "'";
追问
呵呵,不用了,谢谢~~已经找到原因了。不是格式的原因~~
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询