|
-
Nov 17th, 2003, 07:10 AM
#1
Thread Starter
Lively Member
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
-
Nov 17th, 2003, 11:08 AM
#2
Addicted Member
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:
Public Class DB
Public Sub ConnectDB(ByRef CON As Connection)
' Notice that this is a sub that accepts an argument ByRef.
' Read up on passing arguments ByRef if you don't know
' what this does.
'
' Enter DB connection code here.
End Sub
Public Function GetTable(ByVal CON As Connection) As DataSet
' Enter table retrieval code here.
End Function
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
-
Nov 17th, 2003, 02:30 PM
#3
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|