chaitali
September 11th, 2001, 01:43 AM
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.
Cakkie
September 11th, 2001, 03:29 AM
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
slisse@planetinternet.be
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
hitesh_kapadia
September 11th, 2001, 11:16 PM
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