Is there a way to make it so if the employee requested does not exist that the object returns nothing?
Normally I create a Boolean property for Found and check it's value, but I was thinking this would work better, but I don't know what command to put into the else statement to make the "new" object equal nothing.
Is there a way, or should I just create a Boolean for no such employee?
VB Code:
Sub FindEmp() Dim Emp As EmpCL.Emp = New EmpCL.Emp (Me.txtEmpID.Text) If Emp Is Nothing Then MsgBox("Employee Not Found") Else End Sub Public Class Emp Public Name As String Public ID As Integer Sub New(ByVal id As Integer) Dim db As New dbSettings.SQL Dim cn As SqlConnection = New SqlConnection(db.CN) Dim cmd As SqlCommand = New SqlCommand("SELECT * from tblEmp where idEmp = @idEmp", cn) cmd.Parameters.Add("@idEmp", id) cn.Open() Dim dr As SqlDataReader = cmd.ExecuteReader If dr.Read Then Name = dr("Name") ID = id Else 'Me.Dispose() ?? End If End Sub End Class




Reply With Quote