Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing classes - .Net newbie question 1

Status
Not open for further replies.

ericksoda

Programmer
Oct 22, 2001
60
US
I am just learning about vb 2005 and I really like a lot of it. I have a question about the proper use of a class. I have a need to look up a doctor's patient, and other information about the patient( visits, contacts, etc.)

This is what I have so far:
Public Class Patient
Private _PatientId as String
Public Sub New(ByVal PatientId as string)
_PatientId = PatientId
' Query the Oracle database and return the patient record
end sub
Public Property PatientId() as String
Get
PatientId = _PatientId
End Get
Set
_PatientId = PatientId
' Query the Oracle database and return the patient record
End Set
End Property
Public ReadOnly Property Name() as String
Get
Name = ????
End Get
End Property
End Class

My question: Where do I put the query? How do I store the data so I don't have to do a query for every fetch of a property? (I want to update the data in the SET PatientId and the New() modules.)

Thank you for any help!

David
 
Hi,

the following piece of code is just a hint on what you could try, it is not the smartest way to do it but it should help you find your own way of dealing with the problem.


Code:
Public Class Patient

    Private _id As String
    Private _field1 As Integer
    Private _field2 As Integer


    'use this to create a new patient
    Public Sub New()

    End Sub

    'use this to retrieve an existing patient
    Public Sub New(ByVal PatientId As String)
        _id = PatientId
        retrievePatient()
    End Sub

    Public Property ID() As String
        Get
            Return _id
        End Get
        Set(ByVal value As String)
            _id = value
        End Set
    End Property

    Public Property Field1() As Integer
        Get
            Return _field1
        End Get
        Set(ByVal value As Integer)
            _field1 = value
        End Set
    End Property

    Public Property Field2() As Integer
        Get
            Return _field2
        End Get
        Set(ByVal value As Integer)
            _field2 = value
        End Set
    End Property

    Private Sub retrievePatient()

        'query your DB with _id as parameter
        '_field1 = something retrieved from DB
        '_field2 = something retrieved from DB

    End Sub

    Public Sub Add()

        'query to add a new patient

    End Sub

    Public Sub Update()

        'query to update patient

    End Sub

    Public Sub Delete()

        'query to delete patient

    End Sub

End Class


hope it helped
 
Great idea. I had overlooked the obvious. Is there anyway, though, of referring to the fetched recordset? Would a recordset still be 'alive' on subsequent calls to the class?

 
If you want a variable to be common to all instances of a class (that is common to patient1, patient2 etc...) then you can set your recordset as being a 'shared' class member.

here's a link that explains the difference between classes and instances:
and a link for a good explaination of what is a 'shared member' and how to use it.


cheers
 
Mastakilla, Thanks. That is exactly the information I need. Strange how hard it is to find just the right bit of information when you need it.

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top