Implementing OOP to Develop Database Oriented Applications using VB.NET 2005 - Developing a class which holds a set of rows belonging to the same table (Page 3 of 6 )
In the previous section, we saw a class which can store a whole row of information. If we have multiple rows to handle, we need to store them in the form of a collection. The following is the class that can hold multiple objects belonging to the same type:
ImportsSystem.Collections
PublicClass Employees
Inherits CollectionBase
Public Sub add(ByVal e As Employee)
List.Add(e)
End Sub
Public Sub delete(ByVal e As Employee)
List.Remove(e)
End Sub
Public Sub delete(ByVal index As Integer)
If index < 0 Or index > List.Count - 1 Then
Throw New Exception("Invalid index to remove")
End If
List.RemoveAt(index)
End Sub
Default Public Overridable ReadOnly Property Item(ByVal index As Integer) As Employee
Get
Return CType(Me.List(index), Employee)
End Get
End Property
Public ReadOnly Property Search(ByVal Empno As Integer) As Employee
Get
For Each e As Employee In Me.List
If e.Empno = Empno Then Return e
Next
Return Nothing
End Get
End Property
EndClass
Next: Developing a factory class to update rows to the database >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee