Datasheet

diaryDBConn = Nothing
End If
End Sub
The private method UpdateDiaryEntry() updates it:
Private Sub UpdateDiaryEntry()
If mDiaryEntryId <> -1 Then
Dim diaryDBConn As New SqlConnection(conString)
Dim sqlString As String = “UpdateDiaryEntry”
Dim sqlCmd As New SqlCommand(sqlString, diaryDBConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.AddWithValue(“@DiaryEntryId”, mDiaryEntryId)
sqlCmd.Parameters.AddWithValue(“@EntryDate”, mEntryDate)
sqlCmd.Parameters.AddWithValue(“@EntryTitle”, mEntryTitle)
sqlCmd.Parameters.AddWithValue(“@EntryText”, mEntryText)
diaryDBConn.Open()
sqlCmd.ExecuteNonQuery()
diaryDBConn.Close()
sqlCmd = Nothing
diaryDBConn = Nothing
End If
End Sub
Moving on, the next section discusses aspects of the code dealing with editing, viewing, and deleting
events.
Creating, Editing, and Viewing Diary Events
Events are created by clicking the Add New Event link on the DayView.aspx page. This takes you to a
simple form on the AddEvent.aspx page. When the Save button is clicked, the button’s
click event cre-
ates a new
DiaryEvent object, populates its properties from the form, and then calls its Save() method.
The code flow is much the same as for the
DiaryEvent object’s Save() method. Where the functionality
is similar or the same, the names of methods on different objects have been kept the same. It reduces
confusion and makes your life easier.
All events relating to a particular day are shown on the DayView.aspx page. An
ObjectDataSource con-
trol on the DayView.aspx page draws its data from the
DiaryEvent object’s GetDiaryEventsByDate()
shared method. The markup for the ObjectDataSource control is shown here:
<asp:ObjectDataSource ID=”eventsObjectDataSource” runat=”server”
SelectMethod=”GetDiaryEventsByDate”
TypeName=”DiaryEvent” DeleteMethod=”DeleteEvent”>
<SelectParameters>
<asp:SessionParameter DefaultValue=”-1” Name=”DiaryId”
SessionField=”DiaryId” Type=”Int32” />
<asp:ControlParameter ControlID=”dayShownLabel” DefaultValue=””
Name=”FromDate” PropertyName=”Text”
Type=”DateTime” />
<asp:ControlParameter ControlID=”dayShownLabel” DefaultValue=””
Name=”ToDate” PropertyName=”Text”
29
The Online Diary and Organizer
04_749516 ch01.qxp 2/10/06 9:11 PM Page 29