i have a problem generating auto number. can someone help me to solve this?

here is my code

Try
            If IsConnected() = True Then
                strSQL = "Select max(*) from Supplier"
 
            End If
            myCmd.CommandText = strSQL
            myCmd.Connection = myConn
            myDA.SelectCommand = myCmd
            myDR = myCmd.ExecuteReader()
 
 
            If myDR.HasRows Then
                Label5.Text = myDR.Item(0)
            Else
                Label5.Text = myDR.Item(0) + 1
            End If
 
 
 
        Catch ex As Exception
 
        End Try

Hi,

Change the Max selection condition of the SQL query. Try to use the numeric field which holds the auto number in the table.

For example, instead of using

select max(*) from supplier

use as,

select isnull(max(slno),0)[slno] from supplier

Hope this helps.

Thank you.

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.