473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Sharing Data between forms - strong typed

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

Nov 20 '05 #1
3 2411
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.C ount 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" <ct******@pierceassociates.com> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2
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
Nov 20 '05 #3
"Chris Thunell" <ct******@pierceassociates.com> wrote in message news:<ea**************@TK2MSFTNGP09.phx.gbl>...
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/
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

94
by: Gabriel Zachmann | last post by:
Is it correct to say that strong/weak typing does not make a difference if one does not use any pointers (or adress-taking operator)? More concretely, I am thinking particularly of Python vs C++....
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
5
by: Tinius | last post by:
I have created a class which I wish to reuse amongst several projects. But each time I Add the class to a new project, it creates a copy of that class in the folder of the new project. This means...
1
by: Leon_Amirreza | last post by:
Hi, I am wondering if there is a way to share a Dataset object on the main form of my C# App between other forms that I can bind other forms controls to this dataset (designer is not aware of a...
4
by: Khurram | last post by:
Hi, I understand in order to extract data from the tables in a Dataset and setting it to control, the following csharp syntax applies. textBox1.Text = northwindDataSet.Customers.ContactName; ...
7
by: Jason | last post by:
Hello I've got a very simple C# app, that has a datagrid, a text box, and a button which when clicked opens a second form... Form2 frm2 = new Form2(); frm2.Show(); When I place a datagrid,...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.