CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: class modules

  1. #1
    Join Date
    Sep 2001
    Posts
    1

    class modules

    hi,
    i want to know how to write the code of class modules. how to use them in database programming,how to instantiate them.i mean how should i write a code of class modules so that i can call desired fields from the tables.please help me out.
    thank you.





  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: class modules

    This can be done on two ways.

    1) You can create a property for each field in the recordset. This gives a lot of control over the situation, but whenever a field is added, you need to change the class.

    2) You can expose the fields collection of an underlying recordset, or even the entire recordset. This doesn't require you to change the class if you add a field to recordset, but gives you less control, so checks must be done in the application.


    ' 1st example
    Dim myClass1 as new Class1
    myClass1.CustomerID = "ALFKI"

    ' 2nd example
    Dim myClass2 as new Class2
    myClass2.Fields("CustomerID") = "ALFKI"

    ' Class1
    public property get CustomerID() as string
    CustomerID = rst("CustomerID")
    End property
    public property let CustomerID(strID as string)
    rst("CustomerID") = strID
    End property

    ' Class 2
    public property get Fields() as Collection
    set Fields = rst.Fields
    End property
    public property set Fields(flds as Collection)
    set rst.Fields = flds
    End property




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2001
    Posts
    4

    Re: class modules

    You can call the database connection from within your class module & then u can write the normal SQL queries in the functions from within the class module. You can instantiate the class function from your VB form by creating the instance of the class object.

    Hitesh


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

Featured