Re: Global datasets

Tech-Archive recommends: Fix windows errors by optimizing your registry



just add a member variable:

using MyDataSet;
namespace MyPage
{
public class MyPageClass : System.Web.UI.Page
{
private MyDataSet MyDS = null;


private void Page_Load(object sender, eventargs e)
{
MyDS = InitDataSet(); // routine to query and return dataset.

MyDataGrid.DataSource = MyDS;
MyDataGrid.DataBind();
}
}
}



"David Colliver" <DavidColliver@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:61FEC230-CF39-4F9D-AFD5-3985F9E1E573@xxxxxxxxxxxxxxxx
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.Page
{
private void Page_Load(object 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.DataSource = MyDS;
MyDataGrid.DataBind();
}
}
}

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.UserControl
{
private void Page_Load(object 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.DataSource = MyDS;
MyUCDataGrid.DataBind();
}
}
}


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


.



Relevant Pages

  • Re: Global datasets
    ... InitDataSetbe called for every control that uses it, ... using MyDataSet; ... public class MyPageClass: System.Web.UI.Page ... MyDataGrid.DataSource = MyDS; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Global datasets
    ... InitDataSetbe called for every control that uses it, ... using MyDataSet; ... public class MyPageClass: System.Web.UI.Page ... MyDataGrid.DataSource = MyDS; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Global datasets
    ... So, if I need to use it in a user control as well as a page, the user control ... using MyDataSet; ... public class MyPageClass: System.Web.UI.Page ... MyDataGrid.DataSource = MyDS; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Global datasets
    ... namespace MyDataSet ... public class MyPageClass: System.Web.UI.Page ... re-instantiating it. ... MyDataGrid.DataSource = MyDS; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Global datasets
    ... namespace MyDataSet ... public class MyPageClass: System.Web.UI.Page ... re-instantiating it. ... MyDataGrid.DataSource = MyDS; ...
    (microsoft.public.dotnet.framework.aspnet)