- // Get the number of rows (which is zero based).
- int numberOfCookies = countCookiesQuery.at() + 1;
+ // Check to see if the query is valid (there is at least one cookie).
+ if (countCookiesQuery.isValid())
+ {
+ // Move to the last row.
+ countCookiesQuery.last();
+
+ // Get the number of rows (which is zero based) and add one to calculate the number of cookies.
+ numberOfCookies = countCookiesQuery.at() + 1;
+ }