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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating data and Objects

Status
Not open for further replies.

nathj

Programmer
Oct 11, 2004
33
GB
Hi There,
I am developer whose main experience is VFP and am now moving to VB .Net. This is a great idea and I can see all the benefits, the problem is I have very little idea as to what I am doing. The project at the moment is to redevelop our entire product offering in .Net. A main part of this is clients and addresses and I now need to write a function that returns a clients main electronic address (email, telephone, fax URL, etc). I am planning on writing a function for each EAddress type however so far I have managed to get the appropriate data into a new DataTable, this has only the id of the relevant record and I now need to use this ID to createa a new instance of the Eaddress Object to return to the calling function.

It may be that I am not attempting this in the best way and I am open to any suggestions. Here is the code as it stands.

Public Function GetMainEAddress(ByVal eAddressTypeID As Integer, ByVal personID As Integer, ByVal who As Integer) As EAddress
Code:
        ' Parameters explained: eAddressTypeID = The ID from EAddressType to denote the type of EAddress to get. If its 0 then we get all
        '                       nGetType = 1 Get only the main, 2 Get all of this type
        '                       personID = the id for whom to get the eaddress
        '                       who = 1 PersonalDetails, 2 Department, 3 ClientTrust

        Dim eAddressTable As New DataTable
        Dim sQL As String
        Dim MainEmailID As Integer

        Select Case who
            Case 1 ' Person
                sQL = "SELECT eaddress.id from eaddress, personeaddress "
                sQL += "where eaddress.id = personeaddress.eaddressid "
                sQL += "and personeaddress.ismain = true "
                sQL += "and personeaddress.peronaldetailsid = personID "
                sQL += "and personeaddress.eaddresstypeid = eAddressTypeID"
            Case 2 ' Department
                sQL = "SELECT eaddress.id from eaddress, departmenteaddress "
                sQL += "where eaddress.id = departmenteaddress.eaddressid "
                sQL += "and departmenteaddress.ismain = true "
                sQL += "and departmeneaddress.departmenid = personID "
                sQL += "and departmenteaddress.eaddresstypeid = eAddressTypeID"
            Case 3 ' Trust
                sQL = "SELECT eaddress.id from eaddress, trusteaddress "
                sQL += "where eaddress.id = trusteaddress.eaddressid "
                sQL += "and trusteaddress.ismain = true "
                sQL += "and trusteaddress.clientTrustID = personID "
                sQL += "and clienteaddress.eaddresstypeid = eAddressTypeID"
            Case Else
                Throw New ConstraintException("Illegal Model Manipulation")
        End Select


        DataBase.TableFill(sQL, eAddressTable)

        If eAddressTable.Rows.Count = 0 Then
            Throw New ConstraintException("Illegal E-Address Definition")
        End If
        ' TODO Get the resultant table into the required object
        ' Create a new instance of EAddress based on the retreived ID

        Return CType(Factory.Get_Model(GetType(EAddress), 0, Me.RetrievalMethod), EAddress)

    End Function
Any help would be greatly appreciated in my attempt to write this function.

Many thanks
Nathan Davies
 
Nathan

Can you provide more info on what exactly EAddress is. You say its an Object, but that is all encompassing. It would seem good sense to make EAddress a Structure and have the function return a new instance of that Structure.

I have no idea what this line of code does. I presume its a UDF.
Return CType(Factory.Get_Model(GetType(EAddress), 0, Me.RetrievalMethod), EAddress)


PS. I moved across from Foxpro almost 2 years ago now. Some days Im glad I did, other times, things seem so convoluted.


Sweep
...if it works dont mess with it
 
Sweep,
thanks for the reply. the final line of code is a UDF and may or may not be required. EAddress stores all electronic address information, the sort of thing that is not tied to any physical location. Every client is connected to this collection and can have any number of any type of EAddress (sometimes it makes my head hurt to think about this). The plan is to be able to show the main EAddress information for each type be that email, url mobile etc.

I must admit I am struggling to make my question clear but I will do my best. Within the client there is an accessor that aims to show the main email address, this is denoted in the underlying SQL by they relevant type number and the ismain flag set to True. I wish to retreive as an instance of EAddress the main email address. Does this make sense? It would be good if I could draw a digram to explain.
Thanks again for stopping by.
Nathan
 
You say you are getting a record in your datatable. I would guess that it is just the one record in each scenario

If Im reading your posts correctly all you want to be able to do is to access this datatable.
Code:
dim dr as Datarow 
'Get the First Row of the Table
dr = eAddressTable.rows(0)
'Get the Field Contents
dim iId as Integer = cint(dr("idField"))


Sweep
...if it works dont mess with it
 
Sweep,
Thats fantastic. Now I have the Id out I can do all sorts of wonderful things. Thank you very much

Nathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top