User1485238302 posted
This means that a value of type DBNull is returned (may be because you do not have any photos and the procedure is returning null).
You can either use Int32.TryParse or check for DBNull before you do this.
// TryParse
int count;
bool result = Int32.TryParse(e.Command.Parameters["@pageCount"].Value.ToString(), out count);
pages = count;
// OR
if(e.Command.Parameters["@pageCount"].Value != DBNull.Value)
{
pages = Convert.Int32(e.Command.Parameters["@pageCount"].Value);
}