0

Dear Friends,

Good Day,

I am facing an issue in one of the functions the code is given below if someone can help on this actually this function is supposed to check the work ordewr number if it's nulll then it is suppose to take default value as 4999 and add one everytime, but the function is not taking the default value its is starting from 1 and then next record +1 means 2 like this but it supposed to be like 4999+1 means 5000 next record 5000+1 means 5001 like this. Any help in this regard will be highly appriciated. i am using VB.NET with Oracle Database.

Private Function Auto_no() As Integer
        Dim con As New OracleConnection(ConnectionString)
        Dim com As OracleCommand = Nothing
        Dim retVal As Object

        Try
            con.Open()
            com = New OracleCommand("SELECT MAX(WO_NO) FROM WO GROUP BY WO_NO ORDER BY WO_NO DESC", con)
            retVal = com.ExecuteScalar()

            If Not IsDBNull(retVal) Then
                retVal += 1
            Else
                retVal = 4999
            End If

            con.Close()
        Catch ex As OracleException
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            retVal = 4999
        End Try

        Return retVal
    End Function
3
Contributors
4
Replies
30
Views
2 Months
Discussion Span
Last Post by xrj
0

Yes i tried it is showing nothing, means null but then if it's nulll it's suppose to take value 4999 and then add one to make it 5000 but its adding 1 in 0 then next record 1+1=2 and so on.

0

I found out the problem and fixed it i just the retval variable is equal to nothing it worked perfectly.

Anyway thanks for the help.

0

Try the following

            If retVal IsNot DBNull.Value Then
                retVal += 1
            Else
                retVal = 4999
            End If
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.