ExecuteNonQuery returns the number of rows involved in the command. Its probably running your command, but returning 0 since no rows were affected. ExecuteNonQuery should be used for Updates, Inserts, and Deletes, not Selects.
Instead of using cmd5.ExecuteNonQuery(), do this:
int maxID = (int)cmd5.ExecuteScalar();
Then maxID will hold the MaxID value from the query.