Hi Guys, I have also the same problem with waldis I want to increment the max barcode value by 1. Can you help and check my code what is wrong?, My problem was the same as Waldis_1. Thanks in advance for those whose going to help.

Private   Sub autogenerated_Barcode()
conItem.Close()
conItem.Open()

Dim number As Integer

PassCommand.Connection = Me.TimItemTableAdapter.Connection
If PassCommand.Connection.State = ConnectionState.Open Then
    PassCommand.Connection.Close()
End If
PassCommand.Connection.Open()
PassCommand.CommandText = ("Select MAX(Barcode) FROM timitem")
PassAdapter.SelectCommand = PassCommand
PassReader = PassCommand.ExecuteReader
PassReader.Close()
PassCommand.Connection.Close()

If IsDBNull(cmdItem.ExecuteScalar) Then
    number = "Barcode"
    TextBoxBarcode.Text = number
Else
    number = cmdItem.ExecuteScalar + 1
    TextBoxBarcode.Text = number
End If
cmdItem.Dispose()
conItem.Close()
conItem.Dispose()
End Sub

Have you tried to change:
number = cmdItem.ExecuteScalar + 1
into:
number = Int32.Parse(cmdItem.ExecuteScalar) + 1
?

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.