1 class, 1 dataset and 2 forms, oh my!

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Im unsure how to accomplish this so I am hoping that someone will offer up their expertise. So here goes....

On form1,
dim clsSecurity as new Security
A function is called in the Security class, that fills a dataset with all of the employee data. Using the dataset, a combobox is populated.

On form2
I want to use the same dataset in the dataset that was filled on form1, to eliminate server trips, but I can't figure out how to keep the data. If I use dim clsSecurity as new Security, that instantiates another security class, thereby wiping out the data I want to use.

Any help will be greatly appreciated.
 
Is Security your own class? If so then you could declare a second constructor that has a DataSet argument. Your class could then look something like this:
VB.NET:
Public Class Security

    Private data As DataSet

    Public Sub New()
        Me.data = New DataSet
        Me.InitialiseMe()
    End Sub

    Public Sub New(ByVal data As DataSet)
        Me.data = data
        Me.InitialiseMe()
    End Sub

    Private Sub InitialiseMe()
        'Perform main initialisation here
    End Sub

End Class
 
dont forget to make a public (readonly) property of the security class that returns the dataset, or a relevant portion of it so that both your form1 and form2 can use the data. If security is only ever going to be a single instance in your application, you may wish to make it a module instead
 
OK..i'm a wee bit confused. Yes, the Security is my own class. In the InitializeMe Sub, is that where the dataset would be filled? And where would I set something as Public?

__|\__\O/___ <--shark attack :) sorry had to put that in
 
loved the shark attack


you have to decide if the Security class is a sensible place for the dataset to sit. if the dataset is totally about security, and the security class is the central security effort of the app, then it is a sensible place to sit

if on the other hand, the data set contains everything and you wish to have Security purely for employee login, access rights etc, then you should identify the tables in your dataset that pertain to that notion, and include only those in the security class

to give proper details, we really need more info

please provide a list of:

tables in the dataset
the purpose of Security
the purpose of Form1
the purpose of Form2
 
Actually, I think I solved this. Since, I have supervisors and administrators, I'm gonna have to refresh the dataset anyways, depending on who opened the app.

Thanks for the help..
:)
 
Back
Top