Results 1 to 3 of 3

Thread: Best way to retrive data from database trough a class?

  1. #1

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179

    Best way to retrive data from database trough a class?

    Hi

    I was just wondering whats is the best way to retrive data from a database trough a class and return it to the calling client, so far i can only think of two

    1)Retrive data from a database trough a dataadapter and return as datatable.

    2)Retrive data from a database trough dataadapter and assign the return data to the properties of the class, so that the calling client can get the data trough the properties of the class.


    Is there any better way then the one stated above?

    Thanks

  2. #2
    New Member
    Join Date
    Jun 2003
    Posts
    4
    You can do either of those methods.

    You could also use a DataReader which is faster, Particularly if you are storing them in member variables in your class.

    You could also create a strongly typed dataset and use a dataadapter to populate a class inherited from your typed ds.
    "Convenience is not"

  3. #3
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    ...agree with skaterx2 , either method is valid


    method 2 is the 'traditional' way to do it as it fits nicely into the OOP model and diagrams up nicely if your using UML i.e. 1 stateless class per table. Java programmers have traditionally used this method.

    BUT...

    to be honest this method can get messy - loading objects via properties, providing collection classes as containers for these objects etc. etc. can make for excess work, AND no doubt will have a performance overhead. I would, personally, go with method 1. Even though in 'pure' OO design terms it might not be quite right.

    PS.

    In my latest project i fought for using method 1, but we ended up going with what essentially is your method 2 - i am sooo glad i lost!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width