Подводя итог моим комментариям, я буду делать это:
Dim nextId As Integer
Using connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Barbatos\\Desktop\\Book3.xlsx;Extended Properties=Excel 12.0;"),
command As New OleDbCommand("SELECT MAX([ID]) FROM [Sheet1$]", connection)
connection.Open()
Dim currentId = command.ExecuteScalar()
nextId = If(currentId Is DBNull.Value, 1, CInt(currentId) + 1)
End Using
или, если поддерживается, это:
Dim nextId As Integer
Using connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Barbatos\\Desktop\\Book3.xlsx;Extended Properties=Excel 12.0;"),
command As New OleDbCommand("SELECT ISNULL(MAX([ID]), 0) FROM [Sheet1$]", connection)
connection.Open()
nextId = CInt(command.ExecuteScalar()) + 1
End Using