The way you're doing it is a bit convoluted. I'd try the following:
Code:
Dim sqlMax As String = "SELECT MAX(id) AS 'MaxID' FROM passwords"
Dim cmdMax As New OleDb.OleDbCommand(sqlMax, myConnection)
Dim maxId As Integer, maxReader As OleDb.OleDbDataReader
' get next id...
maxReader = cmdMax.ExecuteReader
maxReader.Read()
maxId = maxReader("MaxID") + 1
maxReader.Close()
cmdMax.Dispose()
' insert new row
Dim sqlInsert As String = "INSERT INTO Passwords (Id, Name, Login, Password, Addedby) VALUES ("
sqlInsert = sqlInsert & maxId & ", "
sqlInsert = sqlInsert & TxtName.Text & ", "
sqlInsert = sqlInsert & TxtLogin.Text & ", "
sqlInsert = sqlInsert & TxtPassword.Text & ", "
sqlInsert = sqlInsert & "'Louisa')"
Dim cmdInsert As New OleDb.OleDbCommand(sqlInsert, myConnection)
cmdInsert.ExecuteNonQuery()
cmdInsert.Dispose
This could be improved a bit as well. Really, I'd turn getting the next id into a stored procedure on the server that you can just execute - this will be a bit faster. Also, I'd give the insert command a load of parameters instead of building it line by line as I've done - this won't be very fast either. However, if it isn't a process you're going to repeat a lot, it probably won't matter - it could just be more scalable with the things I've suggested. Oh, one other thing - you'll probably want to put some error handling in there as well, paticularly around the database calls (.ExecuteReader and .ExecuteNonQuery) - and account for a null value coming back for maxId (display an error to the user?).
Jaucourt