Hello. I'm trying to get last record id of a table. I found some code on the net and my code so far:

Code:
If IsTimeExists(currentTime) = True Then

	' If currentTime exists, skip inserting, get last id
	Dim dbStr As String = "SELECT * FROM lastChange_tbl WHERE lastChange = ?"
	' Get last record id
	Dim query2 As String = "Select @@Identity"
	Dim ID As Integer
	Using Connection
		Using command2 As New OleDbCommand(dbStr, Connection)
			command2.Parameters.AddWithValue("", currentTime)
			If Not Connection.State = ConnectionState.Open Then
				Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + appPath + "\pages.mdb"
				Connection.Open()
			End If
			command2.ExecuteNonQuery()
			command2.CommandText = query2
			ID = command2.ExecuteScalar()
		End Using
	End Using

Else
This code inserts new record while I just want to get the last id. How can I fix this?


Edit: It's an Access (mdb) database.