System.InvalidOperationException。转换失败,因为十进制数据值溢出指定的类型

时间:2016-07-28 06:09:36

标签: c# datatable decimal fill invalidoperationexception

我有一个在ms访问中运行没有问题的查询,但是当我从c#winform应用程序运行查询时,它显示以下错误: System.InvalidOperationException:转换失败,因为Decimal数据值溢出了在使用者缓冲区中为Decimal值部分指定的类型。还有一栏'总计'在ms访问查询结果中显示正确,但它在C#datagridview中显示不同的结果。 请参阅查询:

SELECT B.Serial, B.payId, B.invoiceId, B.subTotal, B.discount AS disPercent, (B.subTotal*(discount/100)) AS disAmount, B.total, FORMAT(B.payDate,'dd/MMM/yyyy  hh:mm AM/PM') AS payDate, 
B.amount, B.sumPayments, B.balance, B.remark, 1 AS prevRecord
FROM (SELECT (select  IIF( IsNull( count(*)),'',count(*) ) from payment where A.invoiceId = invoiceId and A.payId>=payid) AS Serial, 
A.payId, 
A.invoiceId, 
(select IIF( IsNull(sum(unitPrice*quantity)),0.0,sum(unitPrice*quantity)) from invoiceDetails where A.invoiceId=invoiceDetails.invoiceId) AS subTotal, 
( select discount from invoice where invoice.invoiceId = A.invoiceId ) AS discount, 
(select total from invoice where A.invoiceId=invoice.invoiceId) AS total, 
A.payDate, A.amount, 
(select  IIf(IsNull(sum(amount)), 0.0, sum(amount))  from payment where A.invoiceId = payment.invoiceId and payment.payId<=A.payId )  as sumPayments,
((select  total from invoice where A.invoiceId=invoice.invoiceId)-(select  IIf(IsNull(sum(amount)), 0.0, sum(amount))  from payment where A.invoiceId = payment.invoiceId and payment.payId<=A.payId )) AS balance, 
A.remark FROM payment AS A
Where A.invoiceId=14
)  AS B;

导致以下结果:

enter image description here

在C#winForm中有两种情况,第一种是以下错误:

enter image description here

或者结果将显示与ms访问中的结果不同:

enter image description here

我不知道为什么会这样。 请帮忙

0 个答案:

没有答案