If a table has no records in it, it returns 0, then add one to it.
Public Function GetID(ByVal TblName As String) As Integer
Dim cn As New db
Dim x As Integer
Dim cmd As New OleDb.OleDbCommand
cmd.Connection = cn.GetConnection ' you can use your own code to connect to the DB
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select max(ID) from " & TblName
cmd.Connection.Open()
x = CInt(IIf(cmd.ExecuteScalar() Is System.DBNull.Value, 0, cmd.ExecuteScalar()))
cmd.Connection.Close()
Return x
End Function
Hope you find it useful.




