As before, you need to make an entry in the database and add some code to frmMain to be able to test your Employee objects. Take the following steps to test the Employee objects:
Rebuild the solution.
Copy the NorthwindDC and NorthwindShared objects to the \bin folder in IIS.
Edit the web.config file and add the following wellknown tag:
<wellknown mode="Singleton" type="NorthwindTraders.NorthwindDC.EmployeeDC, NorthwindDC" objectUri="EmployeeDC.rem"/>
Next, edit frmMain and add a new Case statement to the MainMenu_Click method as follows:
Case "&Employees" LoadEmployees()
Add a new module-level variable to frmMain for the frmEmployeeList form:
Private WithEvents mfrmEmployeeList As frmEmployeeList
Next, add a LoadEmployees method as shown in Listing 9-37.
Listing 9-37: The LoadEmployees Method
Private Sub LoadEmployees() Try If mfrmEmployeeList Is Nothing Then Cursor = Cursors.WaitCursor mfrmEmployeeList = New frmEmployeeList() mfrmEmployeeList.MdiParent = Me mfrmEmployeeList.Show() Else mfrmEmployeeList.Focus() End If Catch exc As Exception LogException(exc) Finally Cursor = Cursors.Default End Try End Sub
The last thing you need to do is add a method that sets the mfrmEmployeeList equal to nothing when the Employee List form closes:
Private Sub mfrmEmployeeList_Closed(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles mfrmEmployeeList.Closed mfrmEmployeeList = Nothing End Sub
Now you can run the application and play with it a little. To see how the server-side errors are handled, change the birth date to the current day. No error will be generated until you click the OK button; then you will see the error returned by the server!
Caution | The beta version of .NET 1.1 this was tested against produced an interesting error. When you try to save an employee record with no photo, it fails. Trying this in version 1.0 worked fine, though. The reason it is failing is because even when you assign a value of DBNull.Value to a photo parameter, it actually assigns a value of "." and there is no way to get rid of it. |