Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2005, 03:41 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Persisting a Dataset in the ViewState object

Hi,

I'm trying to store a small dataset in the ViewState object, so I don't have to repopulate it every time the form is posted back.

After populating the dataset for the first time, I'm able to do a statement like...

ViewState("ds") = ds.GetXml

which stores the dataset as xml inside a string. No problem.

How then can I repopulate the dataset when the page is posted back?

I've got

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IsPostBack = False Then
          'Do all my dataset population stuff here
          ViewState("ds") = ds.GetXml
        Else
           'populate dataset with html from ViewState string
           ds.ReadXml(ViewState("ds"))
        End If

Nope. No dice. ASP.NET doesn't want a string passed into the ReadXml method. It wants an XmlReader. I tried messing around with this a little bit, but got no success. You'd think that if you can write a dataset out to a string, you could then read it from a string.

I just want to store a dataset in a ViewState or Session variable. How do I do this???

Thanks.

Aaron
 End Sub

 
Old March 31st, 2005, 09:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Check that the ViewState("ds") exists first.

Brian
 
Old March 31st, 2005, 09:50 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. It was

       If IsPostBack = False Then
          'Do all my dataset population stuff here
          ViewState("ds") = ds.GetXml
        Else
          'get xml back from ViewState
          Dim vxml As String = ViewState("ds")
          Dim sr As New System.IO.StringReader(vxml)
          'read in XML from stream
          ds.ReadXml(sr)
        End If

It was the old StringReader thing. Seems like a silly extra step to me. If you can write to a string, you ought to be able to read from a string.

Thanks all.

Aaron

 
Old April 13th, 2005, 11:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Or better yet, just store the DataSet object directly to the session. The DataSet stores its data internally as XML anyway so there's probably not much difference between storing as a string of XML from the dataset or the dataset object itself, particularly with a simple single-table dataset.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Persisting Simple Association aadz5 Hibernate 1 August 13th, 2008 03:49 AM
Persist DataSet in ViewState bnorg ASP.NET 2.0 Professional 1 May 22nd, 2007 07:46 AM
Can we use same Dataset Object? gaurav_jain2403 VS.NET 2002/2003 6 February 3rd, 2006 01:49 AM
Newbie who needs help with DataSet object!!! rboyle ADO.NET 1 March 10th, 2004 08:25 PM
Persisting viewstate between pages drettberg ASP.NET 1.0 and 1.1 Professional 3 September 22nd, 2003 11:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.