Results 1 to 3 of 3

Thread: Creating a class for datamanipulation???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84

    Question Creating a class for datamanipulation???

    Hi,

    I have an application which is based on a MSAccess 2000 database with a number of related tables. The application contains some forms which have comboboxes and listboxes that need to give the related values from the tables.

    Now I have in each form created a dataadapter and a dataset for each table I need in that specific form, but I think this produces a lot of overhead code. I was thinking about creating a class that I can reuse in every form. THe class should do the following:
    - create a connection to a database
    - create an oledbdataadapter
    - create a dataset
    - create a listbox that contains the value of the dataset

    Is this possible? How do I have to programm this: do i need a windows form or a class? How can I use the class in the other forms?

    I'm a newbie to OOP, so please give me some hints and a code example if possible?

    Thank you very much for your time;

    Tom

  2. #2
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245

    Re: Creating a class for datamanipulation???

    Originally posted by zozzie
    Hi,

    I have an application which is based on a MSAccess 2000 database with a number of related tables. The application contains some forms which have comboboxes and listboxes that need to give the related values from the tables.

    Now I have in each form created a dataadapter and a dataset for each table I need in that specific form, but I think this produces a lot of overhead code. I was thinking about creating a class that I can reuse in every form. THe class should do the following:
    - create a connection to a database
    - create an oledbdataadapter
    - create a dataset
    - create a listbox that contains the value of the dataset

    Is this possible? How do I have to programm this: do i need a windows form or a class? How can I use the class in the other forms?

    I'm a newbie to OOP, so please give me some hints and a code example if possible?

    Thank you very much for your time;

    Tom
    Yup, you can do this. Create a public class that contains public functions for everything that you wanna do. One thing to note, though, is that it is unneccessary to use a dataset for every table. One dataset can contain multiple tables.

    The class would be something like:

    VB Code:
    1. Public Class DB
    2.     Public Sub ConnectDB(ByRef CON As Connection)
    3.         ' Notice that this is a sub that accepts an argument ByRef.
    4.         ' Read up on passing arguments ByRef if you don't know
    5.         ' what this does.
    6.         '
    7.         ' Enter DB connection code here.
    8.     End Sub
    9.  
    10.     Public Function GetTable(ByVal CON As Connection) As DataSet
    11.         ' Enter table retrieval code here.
    12.     End Function
    13. End Class

    This is just off the top of my head, so it may have syntactical errors. Also, you'll have to add more functions/subs for everything that you wanna do.

    HTH
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    Thanks for your suggestion, I'll try it and I'll keep you informed.

    Tom

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