473,804 Members | 3,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I refrence the same dataset in all forms?

I have a program that has a main form and several modeless forms. I'd
like to access the same dataset that is loaded when the main form loads
from all of the forms - How to do this? In vb.net I just used a module
to start up the main form - that module loaded in the dataset - I
couldn't figure out how to use the same method in C#

~Benny
Nov 16 '05 #1
5 3713

"Benny Raymond" <be***@pocketro cks.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
I have a program that has a main form and several modeless forms. I'd like
to access the same dataset that is loaded when the main form loads from all
of the forms - How to do this? In vb.net I just used a module to start up
the main form - that module loaded in the dataset - I couldn't figure out
how to use the same method in C#

~Benny


Could you create a static class to hold the dataset. IT would be available
to all the forms then.
Nov 16 '05 #2
you can declare a field with static modifer, like is:
public class ClassName
{
public static DateSet s_dateset;
...
}

In the form, you can access the same dateset throught ClassName.s_dat eset.

public class Form1 : System.Windows. Forms.Form
{
...
public void DoSomethin()
{
ClassName.s_dat eset
}
}
I have a program that has a main form and several modeless forms. I'd
like to access the same dataset that is loaded when the main form
loads from all of the forms - How to do this? In vb.net I just used
a module to start up the main form - that module loaded in the
dataset - I couldn't figure out how to use the same method in C#

~Benny


Nov 16 '05 #3
if the dataset is public can't you reference it using something like
frmMain.dataSet ?

"Benny Raymond" <be***@pocketro cks.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
I have a program that has a main form and several modeless forms. I'd like
to access the same dataset that is loaded when the main form loads from all
of the forms - How to do this? In vb.net I just used a module to start up
the main form - that module loaded in the dataset - I couldn't figure out
how to use the same method in C#

~Benny

Nov 16 '05 #4
Just create a public class with a static member of type DataSet, along these
lines:

public Globals {
private static DataSet ds = null;
public static DataSet GlobalDataSet {get {return this.ds;}}

public static Globals() {
// Create the DataSet here. This will run the first time you access
// the GlobalDataSet property (or some other static property you
// might define in this class)
}

}

In your code, you simply reference it like this:

DoSomethingWith (Globals.Global DataSet);

--Bob

"Benny Raymond" <be***@pocketro cks.com> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
I have a program that has a main form and several modeless forms. I'd like
to access the same dataset that is loaded when the main form loads from all
of the forms - How to do this? In vb.net I just used a module to start up
the main form - that module loaded in the dataset - I couldn't figure out
how to use the same method in C#

~Benny

Nov 16 '05 #5
Thanks, everyone. I ended up using this (and it's working great!):

public class DataClass
{
private static cpoundtest.Data set1 s_dataset = null;
public static cpoundtest.Data set1 GlobalDataSet
{
get
{
if (s_dataset == null)
{
s_dataset = new cpoundtest.Data set1();
}
return s_dataset;
}
}
}
Nov 16 '05 #6

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

Similar topics

1
2899
by: Greg Phillips | last post by:
Hello everyone, I have read the section on templates in The C++ Programming Language 3rd edition 3 times over the last 4 days. Still I am stumped. I'll explain a bit about what I am doing before asking the question so as you can understand what I am trying to accomplish. Any help would be much appreciated.
3
13079
by: James Morton | last post by:
I am writing a c# windows forms application. I read in an XML file to a dataset for read-only access (by the user and the application logic). This is not an MDI app but has LOTS of seperate forms. They all need to get to tables within this DataSet. How can I make the DataSet "Global" for all forms within the application. I could just read in the file in every form to a newly instanced dataset (the XML is not that large) but this has...
5
1849
by: Grant | last post by:
Hello, How come when I add a new row to my dataset table it shows up as changed (agencyData.Haschanges() = True) but when I delete a row the dataset thinks here are no changes(agencyData.Haschanges() = False)???? The bizaar thing is the row count before the delete and after is different so it definately is being deleted but I cannot update my main database table because the dataset thinks there are no changes?
0
3506
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. There is nothing crazy about the code. I used the designer to add the dataset and to do the...
2
6905
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the data but then I have other forms that give the ability to add, modify, and delete rows. This of course changes the dataset and I need that reflected in the main form. At first I was actually passing a reference of the dataset to the "modify" form...
161
7898
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
2
2597
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread out the work. The order of work is as follows: 1. Retrieve the data from primary data source 2. Update UI with retrieved data - this is accomplished by passing a dataset as an event parameter
3
14515
by: preitymathur0422 | last post by:
I m working on a MDI application. Here on the parent form I had two variables declared as public int curUserID = 0, ViewUserID = 1; the form is inherited by the "Form" class. I m using these variables on all the other forms. But this gives the warning - "Accessing a member on 'LabTest.frmSBTUSA.ViewUserID' may cause a runtime exception because it is a field of a marshal-by-reference class"
1
2375
by: jonbartlam | last post by:
Hi There I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will need updating with 'CLOSED' where necessary.) I have been trying to use the OLEDB command builder to build the statement to update the database however it is returning an error whenever I try to do this. I already have a dataset full of data, 1...
0
10558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.