How to pass a DataSet between forms?

joyxl

Member
Joined
Dec 18, 2005
Messages
6
Programming Experience
Beginner
I am VB.NET newbie working on a simple Pocket PC application. It will query the database, fills a DataSet and displays it.

I have two forms - one to get the search info and query the database, the other to display the data.

How I am going to pass the data or DataSet over to the other form and display it?

Thanks :)
 
Presumably the first form is creating the second and then displaying it by calling ShowDialog, yes? If so, you would expose the DataSet as a public property in the second form, as ManicCW suggests, so the first form can retrieve it once the second form is dismissed. Note also that if you are only Filling a single DataTable then a DataSet is pointless and you might as well just use a DataTable alone.
 
If you wish to process the dataset to a function in the second form ( including display in a Grid ), then you can pass the DataSet to the function as a parameter and do the needful.

Varadarajan R
 
I declared the DataSet as public in a module.
It works fine, all my forms can access it :)

Thanks for the reply.
 
joyxl said:
I declared the DataSet as public in a module.
It works fine, all my forms can access it :)

Thanks for the reply.
Global variables should only be used where there is not a more appropriate solution, which in this case there is. Using global variables is, in my opinion, lazy programming when there are better alternatives. You could declare everything as a global variable but that's not really good practice, and neither is it good practice to declare individual things as global variables without need.
 
I agree with Joyxl, you should be making your dataset private and adding a public property to expose your dataset in your 2nd form. Set the public property to your dataset with data before create the 2nd form and if you modify the dataset in the 2nd from you can hide the form then read the new value from the public property and the .close() the form.

Food for thought!
 
Back
Top