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

Did you try debugging by printing the value of retVal at line 10?

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.

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.

Try the following

            If retVal IsNot DBNull.Value Then
                retVal += 1
            Else
                retVal = 4999
            End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.