473,651 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global datasets

Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it. If
it has to be created, then I need to do it, but then other controls that use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time MyDS is
needed. When the page is run, I only want to have to go to the database once,
to build my dataset. I want to be able to use that dataset in the page, or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
Nov 14 '06 #1
23 2247
David,

From what I can tell, you're confusing "Global" with "Cached" or "Session"
objects... Are you trying to building a dataset object once, then have
subsequent page refreshes use the cached object?

I punched "ASP.Net session objects" into google and got this link straight
away which goes into the details a bit more...
http://www.aspfree.com/c/a/ASP.NET/A...ts-in-ASP.NET/

If this is not what you want to do, or you want more help on it, let me
know.
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it. If
it has to be created, then I need to do it, but then other controls that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page, or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

Nov 14 '06 #2
Hi,

No, I am not thinking of cache or session. That is not what I want.

I want to create a dataset at the start of the page process. During the
page, I want to use that dataset in many places. The dataset I refer to is
actually a menu system built from the database.

examples of use...

1. Creating a breadcrumb trail.
2. Building the main navigation.
3. Building the sub navigation.
4. Knowing where I am so that objects on the page resond accordingly.

What I don't want (in the above scenario) is to create the dataset 4 times.
I want to use it in 4 places. This can be in the page itself, in can be in
the breadcrumb usercontrol, it can be in the main navigation user control.

There is no point in contacting the database 4 times for exactly the same
data. This is expensive and time consuming. So, I want to create it only once
at "global level" for the page and various page objects use it.

I don't need to cache it (yet anyway). At the moment, I am happy to create
it for every call to the page, but only once in the life of the call to the
page.

How do I do that?
Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
David,

From what I can tell, you're confusing "Global" with "Cached" or "Session"
objects... Are you trying to building a dataset object once, then have
subsequent page refreshes use the cached object?

I punched "ASP.Net session objects" into google and got this link straight
away which goes into the details a bit more...
http://www.aspfree.com/c/a/ASP.NET/A...ts-in-ASP.NET/

If this is not what you want to do, or you want more help on it, let me
know.
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it. If
it has to be created, then I need to do it, but then other controls that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page, or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available


Nov 14 '06 #3
David,

Then I assume that what you mean by global is that during the page loading
sequence, you have different objects that all need the same dataset?

If this is the case, then either create the dataset, and pass it into what
ever objects require it (either setting up a property on that class, or
passing it in as a method parameter), or, create a static instance
(something like a singleton object I suppose) so that each time you need to
reference the dataset, you're getting the same "global" instance.

The first method of doing things is far better... Since everything you've
described is intrinsic to having a datasource, then it makes sense to have a
DataSet property on each class, so that you, as I've said, first create the
dataset you need, calling the database and retrieving the data, then
creating each object and assigning this instance of your dataset to the
property so that each object then can use it in turn...

Doesthis make more sense? If not, keeping asking away!
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:E6******** *************** ***********@mic rosoft.com...
Hi,

No, I am not thinking of cache or session. That is not what I want.

I want to create a dataset at the start of the page process. During the
page, I want to use that dataset in many places. The dataset I refer to is
actually a menu system built from the database.

examples of use...

1. Creating a breadcrumb trail.
2. Building the main navigation.
3. Building the sub navigation.
4. Knowing where I am so that objects on the page resond accordingly.

What I don't want (in the above scenario) is to create the dataset 4
times.
I want to use it in 4 places. This can be in the page itself, in can be in
the breadcrumb usercontrol, it can be in the main navigation user control.

There is no point in contacting the database 4 times for exactly the same
data. This is expensive and time consuming. So, I want to create it only
once
at "global level" for the page and various page objects use it.

I don't need to cache it (yet anyway). At the moment, I am happy to create
it for every call to the page, but only once in the life of the call to
the
page.

How do I do that?
Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
>David,

From what I can tell, you're confusing "Global" with "Cached" or
"Session"
objects... Are you trying to building a dataset object once, then have
subsequent page refreshes use the cached object?

I punched "ASP.Net session objects" into google and got this link
straight
away which goes into the details a bit more...
http://www.aspfree.com/c/a/ASP.NET/A...ts-in-ASP.NET/

If this is not what you want to do, or you want more help on it, let me
know.
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:61******* *************** ************@mi crosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it.
If
it has to be created, then I need to do it, but then other controls
that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time
MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page,
or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available



Nov 14 '06 #4
just add a member variable:

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private MyDataSet MyDS = null;
private void Page_Load(objec t sender, eventargs e)
{
MyDS = InitDataSet(); // routine to query and return dataset.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it. If
it has to be created, then I need to do it, but then other controls that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page, or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available

Nov 14 '06 #5
Hi Bruce,

If I did this, and each of my controls as well did this, then won't the
InitDataSet() be called for every control that uses it, hence re-creating the
dataset each time?

I don't want to be creating a dataset (in the initdataset) for every time I
want to use it...

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"bruce barker (sqlwork.com)" wrote:
just add a member variable:

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private MyDataSet MyDS = null;
private void Page_Load(objec t sender, eventargs e)
{
MyDS = InitDataSet(); // routine to query and return dataset.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it. If
it has to be created, then I need to do it, but then other controls that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass, without
re-instantiating it. If it needs to re-instantiate, then only do it once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page, or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available


Nov 14 '06 #6
Hi Dan,

Thanks for sticking with me on this... your assumption is correct. I just
want to create the dataset once (as it is a database process, hence process
expensive) and be able to use it any time I choose, wether in a page or
control.

For the first method, doesn't that assume that the original dataset class
needs to know what classes will want to use it? The way I am visualising this
is that the dataset pushes its data into the page or user controls... I need
to have the dataset not know what wants to use it, just that it is there for
anything/anybody to use.

I have never (knowingly) written a singleton, so I don't know anything about
these. Can you give me a quick example of how I would write one and how I
would call it from within my pages/controls?

Thank you for the help so far...

Regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
David,

Then I assume that what you mean by global is that during the page loading
sequence, you have different objects that all need the same dataset?

If this is the case, then either create the dataset, and pass it into what
ever objects require it (either setting up a property on that class, or
passing it in as a method parameter), or, create a static instance
(something like a singleton object I suppose) so that each time you need to
reference the dataset, you're getting the same "global" instance.

The first method of doing things is far better... Since everything you've
described is intrinsic to having a datasource, then it makes sense to have a
DataSet property on each class, so that you, as I've said, first create the
dataset you need, calling the database and retrieving the data, then
creating each object and assigning this instance of your dataset to the
property so that each object then can use it in turn...

Doesthis make more sense? If not, keeping asking away!
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:E6******** *************** ***********@mic rosoft.com...
Hi,

No, I am not thinking of cache or session. That is not what I want.

I want to create a dataset at the start of the page process. During the
page, I want to use that dataset in many places. The dataset I refer to is
actually a menu system built from the database.

examples of use...

1. Creating a breadcrumb trail.
2. Building the main navigation.
3. Building the sub navigation.
4. Knowing where I am so that objects on the page resond accordingly.

What I don't want (in the above scenario) is to create the dataset 4
times.
I want to use it in 4 places. This can be in the page itself, in can be in
the breadcrumb usercontrol, it can be in the main navigation user control.

There is no point in contacting the database 4 times for exactly the same
data. This is expensive and time consuming. So, I want to create it only
once
at "global level" for the page and various page objects use it.

I don't need to cache it (yet anyway). At the moment, I am happy to create
it for every call to the page, but only once in the life of the call to
the
page.

How do I do that?
Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
David,

From what I can tell, you're confusing "Global" with "Cached" or
"Session"
objects... Are you trying to building a dataset object once, then have
subsequent page refreshes use the cached object?

I punched "ASP.Net session objects" into google and got this link
straight
away which goes into the details a bit more...
http://www.aspfree.com/c/a/ASP.NET/A...ts-in-ASP.NET/

If this is not what you want to do, or you want more help on it, let me
know.
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it.
If
it has to be created, then I need to do it, but then other controls
that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time
MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page,
or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available


Nov 14 '06 #7

No, Page_Load is run once and so the dataset is created once.
"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:5F******** *************** ***********@mic rosoft.com...
Hi Bruce,

If I did this, and each of my controls as well did this, then won't the
InitDataSet() be called for every control that uses it, hence re-creating
the
dataset each time?

I don't want to be creating a dataset (in the initdataset) for every time
I
want to use it...

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"bruce barker (sqlwork.com)" wrote:
>just add a member variable:

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private MyDataSet MyDS = null;
private void Page_Load(objec t sender, eventargs e)
{
MyDS = InitDataSet(); // routine to query and return dataset.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:61******* *************** ************@mi crosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it.
If
it has to be created, then I need to do it, but then other controls
that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time
MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page,
or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available



Nov 14 '06 #8

Sticking with the first method again. The answer is no. The dataset class
doesn't care who references it. All it knows is that it contains the data in
its own object instance. It's up to the (typically) Page_Load event method
to then decide what controls exist that need this instance, and then assign
the data set to it.
The algorithm for Page_Load would look something like this:

Create my DataSet
Populate my DataSet from the Database

Create my CrumbTrail Object
Assign the Dataset to the CumbTrail Object (something like
CrumbTrailObj.D ataSetProperty)
Do some CrumbTrail "stuff"

Create another control object instance
assign the dataset to this object
Do some processing on this object

etc...

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:E3******** *************** ***********@mic rosoft.com...
Hi Dan,

Thanks for sticking with me on this... your assumption is correct. I just
want to create the dataset once (as it is a database process, hence
process
expensive) and be able to use it any time I choose, wether in a page or
control.

For the first method, doesn't that assume that the original dataset class
needs to know what classes will want to use it? The way I am visualising
this
is that the dataset pushes its data into the page or user controls... I
need
to have the dataset not know what wants to use it, just that it is there
for
anything/anybody to use.

I have never (knowingly) written a singleton, so I don't know anything
about
these. Can you give me a quick example of how I would write one and how I
would call it from within my pages/controls?

Thank you for the help so far...

Regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
>David,

Then I assume that what you mean by global is that during the page
loading
sequence, you have different objects that all need the same dataset?

If this is the case, then either create the dataset, and pass it into
what
ever objects require it (either setting up a property on that class, or
passing it in as a method parameter), or, create a static instance
(something like a singleton object I suppose) so that each time you need
to
reference the dataset, you're getting the same "global" instance.

The first method of doing things is far better... Since everything you've
described is intrinsic to having a datasource, then it makes sense to
have a
DataSet property on each class, so that you, as I've said, first create
the
dataset you need, calling the database and retrieving the data, then
creating each object and assigning this instance of your dataset to the
property so that each object then can use it in turn...

Doesthis make more sense? If not, keeping asking away!
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:E6******* *************** ************@mi crosoft.com...
Hi,

No, I am not thinking of cache or session. That is not what I want.

I want to create a dataset at the start of the page process. During the
page, I want to use that dataset in many places. The dataset I refer to
is
actually a menu system built from the database.

examples of use...

1. Creating a breadcrumb trail.
2. Building the main navigation.
3. Building the sub navigation.
4. Knowing where I am so that objects on the page resond accordingly.

What I don't want (in the above scenario) is to create the dataset 4
times.
I want to use it in 4 places. This can be in the page itself, in can be
in
the breadcrumb usercontrol, it can be in the main navigation user
control.

There is no point in contacting the database 4 times for exactly the
same
data. This is expensive and time consuming. So, I want to create it
only
once
at "global level" for the page and various page objects use it.

I don't need to cache it (yet anyway). At the moment, I am happy to
create
it for every call to the page, but only once in the life of the call to
the
page.

How do I do that?
Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:

David,

From what I can tell, you're confusing "Global" with "Cached" or
"Session"
objects... Are you trying to building a dataset object once, then have
subsequent page refreshes use the cached object?

I punched "ASP.Net session objects" into google and got this link
straight
away which goes into the details a bit more...
http://www.aspfree.com/c/a/ASP.NET/A...ts-in-ASP.NET/

If this is not what you want to do, or you want more help on it, let
me
know.
Thanks.
Dan.

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:61******* *************** ************@mi crosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have
another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page
load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create
it.
If
it has to be created, then I need to do it, but then other controls
that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time
MyDS
is
needed. When the page is run, I only want to have to go to the
database
once,
to build my dataset. I want to be able to use that dataset in the
page,
or
control that the page hosts.

How can I make my dataset "global" and how do I then view the
"global"
dataset in each control without creating a new dataset each time it
is
required?

All help is appreciated. Please do ask me questions if needed so
that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available



Nov 14 '06 #9
So, if I need to use it in a user control as well as a page, the user control
also has a page_load. If I stick the code in the user control the same way,
as well as the page, then the code runs twice (doesn't it?)

What I don't want to do is to have all my controls reference the page. It
has to reference the dataset class (or whatever it is I need to reference...)

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"Dan Bass" wrote:
>
No, Page_Load is run once and so the dataset is created once.
"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in message
news:5F******** *************** ***********@mic rosoft.com...
Hi Bruce,

If I did this, and each of my controls as well did this, then won't the
InitDataSet() be called for every control that uses it, hence re-creating
the
dataset each time?

I don't want to be creating a dataset (in the initdataset) for every time
I
want to use it...

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
"bruce barker (sqlwork.com)" wrote:
just add a member variable:

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private MyDataSet MyDS = null;
private void Page_Load(objec t sender, eventargs e)
{
MyDS = InitDataSet(); // routine to query and return dataset.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

"David Colliver" <Da***********@ discussions.mic rosoft.comwrote in
message
news:61******** *************** ***********@mic rosoft.com...
Hi,

using c#, 1.1

I know that we are not supposed to use global variables etc. in c#

I am having a problem, but not sure how to resolve. I did have another
post
here, but may have over confused things, so I will start afresh.

An example of what I want to do...

namespace MyDataSet
{
public class MyDSClass
{
public DataSet MyDS
{
// Do the dataset stuff.
return MyData;
}
}
}
I want to be able to instantiate the above code only once per page load
and
return a dataset.

in my page...

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.P age
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyDataGrid.Data Source = MyDS;
MyDataGrid.Data Bind();
}
}
}

So, the above code wants to use the dataset, but not have to create it.
If
it has to be created, then I need to do it, but then other controls
that
use
it should not have to re-create it once it has re-created.

using MyDataSet;
namespace MyUC
{
public class MyPageClass : System.Web.UI.U serControl
{
private void Page_Load(objec t sender, eventargs e)
{
// I need to open the dataset created in the MyDSClass,
without
re-instantiating it. If it needs to re-instantiate, then only do it
once.

MyUCDataGrid.Da taSource = MyDS;
MyUCDataGrid.Da taBind();
}
}
}
What I am trying to avoid is to have to go to the database each time
MyDS
is
needed. When the page is run, I only want to have to go to the database
once,
to build my dataset. I want to be able to use that dataset in the page,
or
control that the page hosts.

How can I make my dataset "global" and how do I then view the "global"
dataset in each control without creating a new dataset each time it is
required?

All help is appreciated. Please do ask me questions if needed so that I
can
get this resolved.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available


Nov 14 '06 #10

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

Similar topics

10
1409
by: Charles A. Lackman | last post by:
Hello, I have been working with an application that sends a dataset to other forms that are called from individual DLL's. I have noticed that, a dataset that is passed to another form, when changed, changes the dataset in all of the forms. But, if you send a string to the other forms, that the value is independant on each form.. I.E.
9
2899
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... There are articles on the new TableAdapters where it says that a key new advantage is that a single TableAdapter, which can have multiple queries, can be used on multiple forms. Now that was in an article on using TableAdapters with...
3
1785
by: rwoo_98 | last post by:
Does anyone know the difference between defining a static variable inside Global vs using an Application variable? For example Using a static int variable. public class Global : System.Web.HttpApplication { public static int MaxValue
1
1484
by: frozensnow | last post by:
Hello Group, I am using asp.net 2005 to build a website. I have a global module in my project with functions in it.I am trying to call that function in my code and it says the function could not be found. I put that module in app_code folder . Is there any other change I need to do? One more question is regarding the datasets and datatables. I cannot find those classes in asp.net 2005. Are they declared
1
1778
by: Mark Baldwin | last post by:
Steven Thanks for your reply, however the typed datasets are defined in the web service and there seems to way to open the partial class code window - double clicking on the design surface does nothing. I can do this in the client for a client specific dataset, but not in the web service. -- Best regards Mark Baldwin
9
1936
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
4
1839
by: Infog | last post by:
I think I've somehow missed a basic design principle for storing data from databases. What is the "correct" way to store data that your whole application needs access to, regardless of which forms are open or which class is reading the data? I would like to store datasets apart from forms, but don't know how to create them in their own space so that they can be referenced in code at design time. When I started programming, I was using the...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
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
8701
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
8466
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
8584
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...
1
6158
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
2701
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
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.