1

这是在一个 asp.net 应用程序中

我有这个例外 System.OverflowException: Arithmetic operation resulted in an overflow。但奇怪的是,当调用函数并返回结果时,此错误似乎浮出水面,但如果我直接编写函数代码而不是通过函数,只需将其写在代码下方,它不会产生此错误,请帮助这里是编码

Dim MyItem As New Item    
If MyItem.GetQtyInBin(bran_code.Text, itcode.Text, binloc.Text) <= 0 Then

    ...............

    Exit Sub

这是方法的代码

'this method gets the qty of a certain item in a certainn location and returns it
 Public Function GetQtyInBin(ByVal Branch As String, ByVal Item As Integer, ByVal Bin As String) As Integer

    cn = New OleDb.OleDbConnection("provider=msdaora; Data Source=llmw; User Id=xxxx;Password=xxxx")
    cmd = New OleDb.OleDbCommand("select Qty from Binprmast where Bin_No='" & Bin & "' and item_Code='" & Item & "' and Bran_Code='" & Branch & "'", cn)
    cn.Open()
    Dim qty As Double
    qty = cmd.ExecuteScalar
    Return qty

End Function

4

2 回答 2

0

在您的问题中,GetQtyInBin定义为返回 anInteger但返回值qty定义为 a Double

Double 大于 Integer,因此溢出。

像这样正确

Public Function GetQtyInBin(ByVal Branch As String, ByVal Item As Integer, ByVal Bin As String) As Double
        cn = New OleDb.OleDbConnection("provider=msdaora; Data Source=llmw; User Id=boss;Password=boss")
        cmd = New OleDb.OleDbCommand("select Qty from Binprmast where Bin_No='" & Bin & "' and item_Code='" & Item & "' and Bran_Code='" & Branch & "'", cn)
        cn.Open()
        Dim qty As Double
        qty = cmd.ExecuteScalar
        Return qty
    End Function
于 2012-08-18T04:59:51.547 回答
0

您的函数返回一个整数,但您将返回值设置为 Double。您需要更改其中一个以匹配。

注意:如果您切换 Option Strict On这将不会按原样编译,因此会提醒您注意此错误。

于 2012-08-18T05:02:56.590 回答