Sharing Data between forms - strong typed

  • Thread starter Thread starter Chris Thunell
  • Start date Start date
C

Chris Thunell

I have 2 forms, on 1 form i use the wizards to create a strong typed dataset
with tables from an SQL database... and from that i can do stuff like:
me.daEmployee.fill(me.dataset11.tblEmployee) plus some 3rd party controls
can see it the datatables etc etc.

Is there anyway when i open the second form that this information that has
already been loaded into my in-memory dataset be available on all my other
forms... and still be strong typed. (i think i'm using "strong typed"
wording correctly)

I'm in Vstudio2003 and this is a windows forms project.
Any help would be greatly appreciated!
Chris
 
Hi Chris,

That strongly typed dataset is a class that you can see when you set show
all files in your solution explorer (it is beneath the XDS). Because it is a
seperate class it is usable for all classes. However you have to look in
form1 how to use it.

I hope this helps.

Cor
 
In order for it to be strongly typed, you need to use a Strongly Typed
DataSet. This part seems taken care of. What you should do is stick the
DataSet in a Module or Create it as a Shared Property of a class. Then you
can reference it from anywhere. Say you have a class with a Public Shared
Property of type YourStrongTypedDataset and the class is named DataHolder
and the property is MyDataSet.

In form1 you could reference it by DataHolder.MyDataSet. the same goes for
form2 , form3 or any other object . BC its shared (or static in C#) you
don't declare an instance of it, you just reference it directly. Also,
since you are in vb you could just create a module and reference it from
anywhere as MyDataSet although I think adding the prefix avoids possible
naming collisions and is clearer.

When the app loads you should first load this dataset and set the property.
Thereafter, say you have 3 tables and table 1 had 200 rows. Anywhere you
reference DataHolder.MyDataSet, if you check tables.count you'll see 3. You
can check DataHolder.MyDataSet.StronglyTypedTableName.Rows.Count and you'd
get 100(assuming that table was the table I first mentioned.

You may want to create a TypedDataSet by adding it to your project so it's
its own class and that way you could reuse it later on if need be but that's
a side issue basically unrelated.

If you use the Desginer to build it, it'll be strongly typed so you can
refernce it DataSetName.ActualTableName and ActualTableName will appear in
intellisense (proving the strong typing) as opposed to having the reference
Tabes(0) or Tables("NameYouGaveIt").

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 
Chris Thunell said:
I have 2 forms, on 1 form i use the wizards to create a strong typed dataset
with tables from an SQL database... and from that i can do stuff like:
me.daEmployee.fill(me.dataset11.tblEmployee) plus some 3rd party controls
can see it the datatables etc etc.

Is there anyway when i open the second form that this information that has
already been loaded into my in-memory dataset be available on all my other
forms... and still be strong typed. (i think i'm using "strong typed"
wording correctly)

I'm in Vstudio2003 and this is a windows forms project.
Any help would be greatly appreciated!
Chris

Well, if your dataset is a property or a public variable in form1,
then all form2 needs is a reference to Form1.

Alternately, you could always pass the dataset into form2 using a
property or method on Form2.

Note that if the dataset is in a Shared property of form1, then form2
doesn't need to have a reference to Form1 - but be careful with the
shared property's lifecycle. (Note that a Shared New constructor is
only called the first time an object of that class is created, which
is awful helpful for dealing with shared data.)

John Fiala
jcfiala523-at-hotmail.com
http://www.livejournal.com/users/fiala_tech/
 
Back
Top