object oriented question - pass dataset to a class and back

G

Guest

I have a class that performs a few methods on a dataset. That dataset then
fills a grid on a form. What I would like to do is to assign a particular
dataset to the class at runtime.

For instance, if I have 5 datasets named dataset1 through dataset5, how can
I call the class from my form, pass the dataset I want to manipulate and then
bind that dataset to a datagrid on the form?

Each dataset will bind to its own datagrid. Any ideas?

Thanks
 
W

W.G. Ryan MVP

Have you checked out the Microsoft Data Access Applicaiton Block -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/daab.asp

It essentially handles this for you. But essentially you can just pass in
the datasets just like any other object. You can create a collection if
you'd like to hold those datasets so that you can iterate through them.

Can you tell me a little more about the problem and I'll probably be able to
help out a little more.
 
G

Guest

Thanks for responding.
In this instance I am not using a database as such. I am parsing out
delimited files and feeding them into a datatable. I am very comfortable in
ADO.net and so I dump the files into that. However, I need to calculate
against data in these fields. Simple enough to do but I am trying for code
reuse. Essentially, I have a class that consumes the data from the text file
and places the values in the proper place in the datatable.

Here is an example of the call
Dim parsedif as new App.DIF2Dataset
Dim openfile As New OpenFileDialog
openfile.Filter = "DIF files (*.dif)|*.dif"
openfile.ShowDialog()
If openfile.FileName <> Nothing Then
parsedif.Input = openfile.FileName
End If
parsedif.Output = App.dtRCGDIF 'This is the target datatable
parsedif.Parse() 'This is the method to
consume and structure the data.
MsgBox(dtRCGDIF.Rows(1).Item(2)) 'here it fails. The output property
is just a way to point at a public datatable. This class is simply for
gathering the data and making it something I can easily navigate through. The
error is "System.NullReferenceException".

How is it losing its reference when the datatable is public? (it is in a
module btw)

How do I access a dataset or datatable from any class in an application,
change it, and access it somewhere else?

thanks again
 
S

SP

Andrew Carlson said:
Thanks for responding.
In this instance I am not using a database as such. I am parsing out
delimited files and feeding them into a datatable. I am very comfortable
in
ADO.net and so I dump the files into that. However, I need to calculate
against data in these fields. Simple enough to do but I am trying for code
reuse. Essentially, I have a class that consumes the data from the text
file
and places the values in the proper place in the datatable.

Here is an example of the call
Dim parsedif as new App.DIF2Dataset
Dim openfile As New OpenFileDialog
openfile.Filter = "DIF files (*.dif)|*.dif"
openfile.ShowDialog()
If openfile.FileName <> Nothing Then
parsedif.Input = openfile.FileName
End If
parsedif.Output = App.dtRCGDIF 'This is the target datatable

This appears to be incorrect. I would expect something more like
App.dtRCGDIF = parsedif.Parse();

or

parsedif.Parse()
App.dtRCGDIF = parseDif.Output
 
G

Guest

I apoligize for the confusion. Although this says .Output, I am setting a
property in the class. I am telling the class what datatable to use. When the
..Parse method is done, the datatable should be available to bind to a
datagrid. However, it is not. That is where I am stuck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top