473,395 Members | 1,649 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,395 software developers and data experts.

Dataset persistence???

I am having problems understanding how to access a datasource only
once, fill a single dataset, and then reference that dataset multiple
times through different user controls(ascx) found on the same page.

My main page(aspx) contains multiple user controls. The main page also
contains a publicly declared dataset. At the first instance of needing
data I call (from an ascx) a function that fills the dataset and then
returns it to the calling user control. Every instance after that I
would like to call a function that just returns the data that has
already been populated in the dataset. But the dataset is empty. I
have to go back to the datasource everytime. How can I make the
dataset persistent without storing it in something that will use up
resources like a session variable?

Here are some examples of the code in question:

'(Main.ASPX.vb) DsAdmin_ is publicly defined at the top of the class.

Function CreateDataSource(ByVal strdTable As String, ByVal strSQL As
String) As DataSet
Dim ErrMsg As String = Nothing
Try
objData.OpenConn()
Dim objCmd As New SqlClient.SqlDataAdapter(strSQL,
objData.Conn)
objCmd.Fill(DsAdmin_, strdTable)
CreateDataSource = DsAdmin_
Catch exp As Exception
ErrMsg = Err.Description & Err.Source
End Try
objData.CloseConn(
End Function

Public Function GetData() As DataSet
GetData = DsAdmin_
End Function
'code snippets from UserControl1.ascx.vb: This control returns data.
DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.CreateDataSource("dtblUser", "Execute
sp_Admin_GetUserDetails " & (Request("id"))

'code snippets from UserControl2.ascx.vb: This dataset is empty.
DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.GetData()
Any help would be GREATLY Appreciated!!!
Nov 17 '05 #1
5 3673
You have to manually save the filled dataset somewhere...
You can choose between Session, ViewState, Cache or hard
disk, depending of your scenario (Small datasets go well
in viewstate, datasets that should be available to all
users might go to hard drive or Cache object, etc...). A
simple code would be:

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DataSet myDataSet = new DataSet();
fill(myDataSet); //<-- This is a method where
you fill your dataset
Session["myDataSet"] = myDataSet; //<- here we
are saving the dataset for later retrieval.
}
else
{
myDataSet = (DataSet)Session["myDataSet"];
}
myDataSetManupulationMethod(myDataSet); //<-- the
dataset will be available and filled regardless is a
postback or not.
}

P.D.: Sorry about the examples in C#, but i don't write
VB.NET code.
-----Original Message-----
I am having problems understanding how to access a datasource onlyonce, fill a single dataset, and then reference that dataset multipletimes through different user controls(ascx) found on the same page.
My main page(aspx) contains multiple user controls. The main page alsocontains a publicly declared dataset. At the first instance of needingdata I call (from an ascx) a function that fills the dataset and thenreturns it to the calling user control. Every instance after that Iwould like to call a function that just returns the data that hasalready been populated in the dataset. But the dataset is empty. Ihave to go back to the datasource everytime. How can I make thedataset persistent without storing it in something that will use upresources like a session variable?

Here are some examples of the code in question:

'(Main.ASPX.vb) DsAdmin_ is publicly defined at the top of the class.
Function CreateDataSource(ByVal strdTable As String, ByVal strSQL AsString) As DataSet
Dim ErrMsg As String = Nothing
Try
objData.OpenConn()
Dim objCmd As New SqlClient.SqlDataAdapter (strSQL,objData.Conn)
objCmd.Fill(DsAdmin_, strdTable)
CreateDataSource = DsAdmin_
Catch exp As Exception
ErrMsg = Err.Description & Err.Source
End Try
objData.CloseConn(
End Function

Public Function GetData() As DataSet
GetData = DsAdmin_
End Function
'code snippets from UserControl1.ascx.vb: This control returns data.DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.CreateDataSource("dtblUser", "Execute
sp_Admin_GetUserDetails " & (Request("id"))

'code snippets from UserControl2.ascx.vb: This dataset is empty.DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.GetData()
Any help would be GREATLY Appreciated!!!
.

Nov 17 '05 #2
I am not certain that you will like the answer but...

If you want the DataSet to exist between server roundtrips then you
need to save it somewhere. The only places are:
1) In ViewState
2) In Session
3) Some other handrolled storage
4) Refresh from the DB.

If you have a lot of data (100's or 1000's or rows) then 1 & 2 don't
work too well (notwithstanding do you really need/use all the data).
Many people frown on Session anyway as unscalable - but probably ok
for a small intranet app. Why do 3 when 4 is probably quicker.

It may seem inefficient but is probably most scalable to refresh data
from db on each page request and spend your time making certain you
only get the minimum data. Only if your data source is very slow
would it be worth doing your own storage, like writing/reading a temp
XML file, and this may not be scalable.

HTH
Charles

"Jason" <ja***@yoursolution.com> wrote in message
news:b8**************************@posting.google.c om...
I am having problems understanding how to access a datasource only
once, fill a single dataset, and then reference that dataset multiple times through different user controls(ascx) found on the same page.

My main page(aspx) contains multiple user controls. The main page also contains a publicly declared dataset. At the first instance of needing data I call (from an ascx) a function that fills the dataset and then returns it to the calling user control. Every instance after that I
would like to call a function that just returns the data that has
already been populated in the dataset. But the dataset is empty. I
have to go back to the datasource everytime. How can I make the
dataset persistent without storing it in something that will use up
resources like a session variable?

Here are some examples of the code in question:

'(Main.ASPX.vb) DsAdmin_ is publicly defined at the top of the class.
Function CreateDataSource(ByVal strdTable As String, ByVal strSQL As
String) As DataSet
Dim ErrMsg As String = Nothing
Try
objData.OpenConn()
Dim objCmd As New SqlClient.SqlDataAdapter(strSQL,
objData.Conn)
objCmd.Fill(DsAdmin_, strdTable)
CreateDataSource = DsAdmin_
Catch exp As Exception
ErrMsg = Err.Description & Err.Source
End Try
objData.CloseConn(
End Function

Public Function GetData() As DataSet
GetData = DsAdmin_
End Function
'code snippets from UserControl1.ascx.vb: This control returns data.
DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.CreateDataSource("dtblUser", "Execute
sp_Admin_GetUserDetails " & (Request("id"))

'code snippets from UserControl2.ascx.vb: This dataset is empty.
DSAdmin_ is locally defined in a sub of this control.

Public Main As New MyProject.Main

DsAdmin_ = Main.GetData()
Any help would be GREATLY Appreciated!!!

Nov 17 '05 #3
Thank you for your replay. Is it necessary to save the dataset in a
session variable if I am not going back to the client until all of my
user controls are processed? All my user controls are being called by
the server without a post back. They are setup as modules in one aspx
page.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
No - if you are processing the dataset multiple times in one round
trip then populate the dataset once and pass a reference to your
controls. Obvious strategies for this is to have a 'Show' method for
each control which takes a refrence to a data set as a a parameter.
Each control can process the data set immediately or hold the
reference until it needs to process it. Or you can make the data set
a public property of the containing page and pass a reference to the
page to the controls (in Page_Load or OnInit). Be careful to program
defensively as these refrences will be null after any post-back. The
public property is more defensive as you can code like:

private MyDataSet _myDataSet;
public MyDataSet Data {
get {
if( _myDataSet == null )
_myDataSet = InitialiaseDataSet();
return _myDataSet;
}
}

The best being that you never return a null, the worst being you
initialise the data once on each page request. You can refine the
InitialiseDataSet to be the best strategy (ViewState, Session, DB,
other).

HTH,
Charles

"Jason Honn" <ja***@yoursolution.com> wrote in message
news:un**************@TK2MSFTNGP09.phx.gbl...
Thank you for your replay. Is it necessary to save the dataset in a
session variable if I am not going back to the client until all of my user controls are processed? All my user controls are being called by the server without a post back. They are setup as modules in one aspx page.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #5
Charles,

That is exactly what I am after. Is there a more complete example of
what you are describing somewhere that I could look at?(VB or C#) I am
very new to the .Net environment, so anything would help.

Thanks again
Jason

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #6

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

Similar topics

6
by: Paolo Losi | last post by:
Hi all, I'm pretty new to the python language so please excuse me if this is FAQ... I'm very glad to be part of the list! :-) I'm looking into a way to implement a generic workflow framework...
4
by: Bas Hamer | last post by:
I guess I don't know how to word it better than that. Our company has machines that generate log file in our own proprietary language. A while back I wrote a class that took one of these files...
10
by: Simon Harvey | last post by:
Hi everyone, Can anyone tell me if I declare a global variable in my pages code behind, is it persisted if the page does a post back, or do I need to add the object to the session object in...
2
by: Daz | last post by:
I want to make changes to a dataset that is bound to a datagrid. Rather than store the dataset in session between page calls I've found that I can cast the DataSource of the grid back to a DataSet...
2
by: dkode | last post by:
Hello, I am laying out the architecture for a very large website that will scale to a very large degree. I have a couple of questions before I attempt to go and implement a Broker/Persistence...
5
by: Istvan Loerincz | last post by:
Can somebody argue why its good to use Datasets to save XML data ? The flexibility of XML is gone, if I do that. I have an XML file, which I have to read in and work with. So I ask myself...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone? Which is considered to be the 'best' way to cache a dataset and/or a crystal reports reportdocument object? ViewState? Session? Something else? Thanks in advance!
2
by: Mr. Arnold | last post by:
I am working a C# project that uses what's in the subject. I kind of have the basics down on reading the table data. I don't use the above methods of data access or persistence, but I am stuck...
0
myusernotyours
by: myusernotyours | last post by:
Hi all, Am trying to create a Java Desktop App that uses Java Persistence in Netbeans. The database is MS Access but I tried with Mysql and got the same error. When I run the app( Create the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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,...

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.