Question Inheritance help needed

Rad

Member
Joined
Feb 26, 2009
Messages
8
Programming Experience
5-10
I have a base class where amongst other code I have declared 2 properties. In my derived class, I get data from the DB and assign the results to the base class properties. This is so when I go back to the base class code, I can access the property values. It allows me to set the values in the derived class but once I go back to the Base class, the values don't exist.

snippets of code sample:
base class:
VB.NET:
Public Class ServiceProcessor
    Private mSalesOrderID As Integer = 0
    Private mName As String = ""

    Friend Property SalesOrderID() As Integer
        Get
            Return mSalesOrderID
        End Get
        Set(ByVal value As Integer)
            mSalesOrderID = value
        End Set
    End Property

    Friend Property Name() As String
        Get
            Return mName
        End Get
        Set(ByVal value As String)
            mName = value
        End Set
    End Property

derived class:
VB.NET:
Public Class DBCaller

    Inherits ServiceProcessor

    Friend Sub GetData()

        Try

            Dim Conn As SqlConnection = New SqlConnection(SQLConn)
            Dim Cmd As SqlCommand = New SqlCommand("usp_GetData", Conn)

            'open the conn and get the datareader
            Conn.Open()
            Dim Reader As SqlDataReader = Cmd.ExecuteReader()

            If Reader.Read Then
                MyBase.SalesOrderID = Reader("SalesOrderID")
                MyBase.Name= Reader("Name")
            End If

            Reader.Close()
            Conn.Close()
 
vb.net Inheritance help needed

Basically, I need to set properties that exist in the base class from the derived class.
I can see the properties from within the derived class and can set them within the derived class but once I exit and go back to the base class, the values are no more.

Hope someone can help.
 
What do you mean "exit and go back" ?
 
sorry, didn't explain it properly. Will try again.
call starts in ServiceProcessor, then accesses DBCaller.GetData and gets values from the DB and assign the values to the properties of ServiceProcessor. When we have finished with DBCaller.GetData, we go back to ServiceProcessor and here the properties have no values.
 
If I understand you correctly then the only reason is that no value has been set.
 
Try this code in GetData method:
VB.NET:
MyBase.Name = "hello world"
Would this still give you trouble with the inherited property?

If you also wonder about data access try the Data Access forum or one of forums in Database forums.
 
yes, tried that and still the same.
This issue isn't really about data access but more about inheritance I feel.

Easy option would be to forget about inheritance and move the properties to DBCaller and call them from ServiceProcessor. Would you agree?
 
I really don't see the problem with inheritance, perhaps you can provide a basic code sample that reproduce your problem?
 
Back
Top