Array Objects and datasets...how to fill one with the other?

Hi all,
Hopefully I'll ask this correctly.  Here goes...

In vb.net, I've created an "email" object in a class by itself.   Call it email.vb.   I want to be able to use this object as an array, holding multiple "email addresses".  Specifically, I'm wanting to be able to fill this "email address array" with the rows from a populated dataset containing the same field counts and (and data types...strings, in this case).

1) Can I fill this email object with the rows of the dataset without iterating through the dataset row by row?   How?
2) Conversely, can I fill a dataset with a populated email object array in a similar manner?  How?


Below, I've pasted in my code for my "email" object for mutual reference.  If my email object is not 'built' right to be used as an array, please show me the err of my ways.

Your input is appreciated!!!
Terry


Public Class Email
    Private _email_address As String
    Private _email_name As String
    Public Property EmailAddress() As String
        Get
            Return _email_address
        End Get
        Set(ByVal Value As String)
            _email_address = Value
        End Set
    End Property
    Public Property EmailUserName() As String
        Get
            Return _email_name
        End Get
        Set(ByVal Value As String)
            _email_name = Value
        End Set
    End Property
End Class
colepcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

123654789987Commented:
U should create a collection object like EmailList to create a collection of Email object. U can use a ArrayList as a collection.

Dim emailObject as new Email

emailObject.EmailAddress = "abc@com"
emailObject.EmailuserName = "abc"
Dim emailList as new ArrayList.
emailList.Insert(emailObject)
0
colepcAuthor Commented:
Cool.  How could I pass that to a dataset (and a dataset to the emaillist)?
0
GlomCommented:
Hi,
For this purpose, I actually use one method that you will have to write in your Email class :

Public Sub Fill(ByRef DR as DataRow)
    Me.EmailAddress = DR("Address") ' Address is the name of the field in the database.
    Me.EmailUserName = DR("UserName")
    ...
End Sub

and then call it for each row of your DataSet :

Dim DR as DataRow
Dim DS as DataSet ' Your DataSet
Dim emailObject as Email

For Each DR in DS.Tables(TABLE_NAME).Rows
    emailObject = New Email()
    emailObject.Fill(DR)
Next
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

colepcAuthor Commented:
Glom, when interating through "for each dr in ds.tables...", will each iteration add another 'item' to the emailobject?  In other words, I'm assuming that the emailobject's upper bound will grow by 1 on each iteration.  Am I misreading that?
0
colepcAuthor Commented:
I just read my goofy comment above.  Please ignore that.
0
colepcAuthor Commented:
How would I fill the email object with multiple "records" (consisting each of name, and address) from a dataset?
0
GlomCommented:
You cannot simply fill one email object with the entire dataset. You would have to create an email object collection class.

Public Class EmailCollection
Inherits CollectionBase
   
    Default Public Property Item(ByVal index As Integer) As Email
        Get
            Return CType(List(index), Email)
        End Get
        Set(ByVal Value As Email)
            List(index) = Value
        End Set
    End Property

    Public Function Add(ByVal value As Email) As Integer
        Return List.Add(value)
    End Function 'Add


    ' ... And the other methods you need ...
    ' Also :
    Public Sub Fill(Byref DS as DataSet)
        Dim DR as DataRow
        Dim newEmail as Email

        For Each DR in DS.Tables(TABLE_NAME).Rows
            newEmail = new Email()
            newEmail.Fill(DR)
            Me.Add(newEmail)
        Next
    End Sub
End Class

Then after calling the Fill function in your EmailCollection object, you will have the entire content of your dataset, but in object representation.

I hope this will fit what you need.

Glom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
colepcAuthor Commented:
Glom,
thanks for your input, however, I'm afraid I still don't get it.  I've got more homework to do, it appears.  I'll refer back to your examples after I've understood abit more about .net.  Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.