Link to home
Create AccountLog in
Avatar of thenthorn1010
thenthorn1010Flag for United States of America

asked on

How to Write a New Address sub-Class that Uses a DataReader and Can be Passed to a class in VB.NET

I am attempting to write my attached code in a method that allows one to reuse the code to only call the address and related fields once and have a header class inherit the sub-address classes. I am a little confused on how to write the sub-address class to also have a DataReader on it so that it can be used when the original class is used to read in data from a SQL Server Database.
Namespace PO

    Public Class EDIAckHeader

        Dim strRecordType As String
        Dim strCustomerNumber As String
        Dim strChangeFlag As String
        Dim strOrderNumber As String
        Dim strOrderDate As String
        Dim strShipVia As String
        Dim strCustomerPONumber As String
        Dim strCustomerPOReleaseNumber As String
        Dim strPODate As String
        Dim strSystemDate As String
        Dim strSystemTime As String
        Dim strGSSenderID As String
        Dim strTD5DNSNumber As String
        Dim strTradingPartnerName As String
        Dim strDocument_TransactionID As String
        Dim strReceiverID As String
        Dim strSenderID As String
        Dim strSupplierName As String
        Dim strSupplierAddress1 As String
        Dim strSupplierAddress2 As String
        Dim strSupplierCity As String
        Dim strSupplierState As String
        Dim strSupplierZipCode As String
        Dim strSupplierCountry As String
        Dim strSupplierIDQualifier As String
        Dim strShipperName As String
        Dim strShipperAddress1 As String
        Dim strShipperAddress2 As String
        Dim strShipperCity As String
        Dim strShipperState As String
        Dim strShipperZipCode As String
        Dim strShipperCountry As String
        Dim strShipperParterID As String
        Dim strShipperIDQualifier As String
        Dim strReceiverName As String
        Dim strReceiverAddress1 As String
        Dim strReceiverAddress2 As String
        Dim strReceiverCity As String
        Dim strReceiverState As String
        Dim strReceiverCountry As String
        Dim strReceiverParterID As String
        Dim strReceiverIDQualifier As String

        Private Sub New()
            ' Instantiate the output variables that will be used by the class
            strRecordType = ""
            strCustomerNumber = ""
            strChangeFlag = ""
            strOrderNumber = ""
            strOrderDate = ""
            strShipVia = ""
            strCustomerPONumber = ""
            strCustomerPOReleaseNumber = ""
            strPODate = ""
            strSystemDate = ""
            strSystemTime = ""
            strGSSenderID = ""
            strTD5DNSNumber = ""
            strTradingPartnerName = ""
            strDocument_TransactionID = ""
            strReceiverID = ""
            strSenderID = ""
            strSupplierName = ""
            strSupplierAddress1 = ""
            strSupplierAddress2 = ""
            strSupplierCity = ""
            strSupplierState = ""
            strSupplierZipCode = ""
            strSupplierCountry = ""
            strSupplierIDQualifier = ""
            strShipperName = ""
            strShipperAddress1 = ""
            strShipperAddress2 = ""
            strShipperCity = ""
            strShipperState = ""
            strShipperZipCode = ""
            strShipperCountry = ""
            strShipperParterID = ""
            strShipperIDQualifier = ""
            strReceiverName = ""
            strReceiverAddress1 = ""
            strReceiverAddress2 = ""
            strReceiverCity = ""
            strReceiverState = ""
            strReceiverCountry = ""
            strReceiverParterID = ""
            strReceiverIDQualifier = ""
        End Sub
    End Class
End Namespace

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ToddBeaulieu
ToddBeaulieu
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of thenthorn1010

ASKER

Thank you for helping me get started on the process. I have split the one class into the attached two classes to this message posting. My next question is how should the data reader be setup so that it reads in default "Nothing" values to start off with before it passes through the code that will read in the data from the SQL database?
EDIAckHeader.vb
EDIAckAddress.vb
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
This is the first time that I have used a DataReader in VB.NET, as I am used to binding the data fields together. SInce this is being done in a class, I am attempting to use a DataReader for the first time. I thought that you still needed to initialize the properties that you have from the entity and the child-class in the constructor. If the DataReader is already setting them equal to IsNothing, than you are correct that nothing needs to be done with the variables in the constructor.

If the constructor does not need to initialize the values, since the DataReader is going to do it, how would you go about declaring the EDIAckHeader class, which was attached to the previous posting, using the DataReader to fill in all of the properties that are inside of the class along with the EDIAckAddress class, wihch is the child class to the EDIAckHeader class?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks for the help. All of the info you have provided has given me the direction I needed in order to finish the classes and get the data. Thanks again.