G
Guest
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
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