Datasheet

Along with the Item() property, the DiaryEntryCollection class has three public methods:
Method Return Type Description
Add(ByVal New DiaryEntry None Adds a DiaryEntry object to the collection
As DiaryEntry) held by the DiaryEntryCollection
object.
Add(ByVal DiaryEntryId None Creates a new DiaryEntry object.
As Long) DiaryEntryId is passed to the
DiaryEntry object’s constructor to ensure
it’s populated with the diary entry’s details
from the database. The new
DiaryEntry
object is then added to the collection main-
tained by the
DiaryEntryCollection
object.
Remove(ByVal Index as None Removes the DiaryEntry object from the
Integer) collection at the specified index.
So far the classes dealing with contacts and diary entries have been discussed. The next section discusses
the diary events.
The DiaryEvent Class
The DiaryEvent class objectifies a single entry in a diary. It encapsulates everything to do with diary
entries, including creating, updating, and retrieving diary events data. It handles all the database access
for diary events.
The
DiaryEvent class has three constructors, outlined as follows:
Constructor Description
New(ByVal Diaryid as Integer) Creates a new DiaryEvent object with all properties set to
their default values.
New(ByVal EntryId As Long) Creates a new DiaryEvent object with its properties
retrieved from the database using the argument EventId.
New(ByVal DiaryId AS Integer, Creates a new DiaryEvent object with its properties
ByVal EventDate As Date) retrieved from the database using a combination of the
arguments DiaryId and EventDate.
Having created a
DiaryEvent object, saving it involves simply calling the Save() method. The class
will work out whether it’s a new diary event to insert into the database, or an existing one in need of
updating. The
DiaryEvent class also has two Delete() methods. One is a shared method and therefore
doesn’t require a
DiaryEvent to be created, and requires an EventId parameter. It’s used by some of
the built-in data access components provided with ASP.NET 2.0. The second is an object method that
deletes the event referenced by the current
DiaryEvent object. As well as enabling the details of one
diary entry to be retrieved, the
DiaryEvent class provides additional methods for getting details of a
number of diary events as either a collection or as a DataSet by returning a
SqlDataReader object.
14
Chapter 1
04_749516 ch01.qxp 2/10/06 9:11 PM Page 14