Life of a Dataset

Results 1 to 3 of 3

Thread: Life of a Dataset

  1. #1
    Join Date
    Dec 1969

    Default Life of a Dataset

    I have a page that utilizes a user control that I've developed. The user control creates a dataset and populates a couple listboxes that exist within the control. The control also has a drop down list that I want to post back and repopulate the list boxes when it is changed. I am having trouble keeping my dataset, even though I declare it as a public variable in my control class. When the post back occurs, my dataset no longer exists. Is it that supposed to happen? It was my understanding that one of the key advantages of ADO.Net is that you can grab a dataset, close the connection to the database, and keep that dataset in memory for later use. Am I Wrong?

  2. #2
    Join Date
    Dec 1969

    Default RE: Life of a Dataset

    The dataset is kept in memory for only as long as the page is being loaded. Once the page is sent to the browser the dataset no longer exists. If you want to one grab the dataset once then you should look into using the cache which is way faster then querying the database over and over. Hope that helps

  3. #3
    Join Date
    Dec 1969

    Default RE: You have to persist the dataset

    With .Net, like any other browser application, the page is gone when you leave it (like a round trip to the server). If you want to only pull the data from the source and keep it between server trips you must presist the data in some way.<BR><BR>Net offers several choices including ViewState, Session and Cache. Each has advantages and disadvantages.<BR><BR>You can place a dataset into viewstate in the form of an XML string. You can then retrieve it and recreate the dataset during the page_load event. The downside of this is that ViewState is a hidden field on your page so you&#039;re lugging the XML string to the server and back. With a small dataset, this may not pose a performance problem, but a large dataset converted to a string has to have some performance impacts.<BR><BR>To use viewstate to save a dataset convert it to an XML string<BR><BR>Dim strData as String = dataset_Name.GetXml()<BR>ViewState("MyData") = strData<BR><BR>To get it back, put something like this in the page_load sub:<BR><BR>Dim strXML as String = ViewState("MyData").ToString()<BR>Dim strReader As New System.IO.StringReader(strXML)<BR>dataset_name.Rea dxml(strReader)<BR><BR>You can also save objects (like datasets) to Cache. The down side of this is that if you have multiple users at the same time you need to create a session-specific name for each user&#039;s dataset object. This is usually done by concatanating the session ID to the variable name you use for the dataset.<BR><BR>Putting a dataset into a session variable is pretty straight forward, but session objects tend to be frowned on relative to best practice.<BR><BR>Any one of the three methods will let you pull from the data source once and keep the dataset between posts to the server.<BR><BR>Good luck<BR><BR>TT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts