View State on Dataset Does Not Work

B

Bruce LeMond

I copied the code to save and restore the view state of a
dataset from the Visual Studio help screen. I Modified it
to the dataset I want. But when I run, I received an
error message. Here is the code I have:

Private Sub RoomSelect_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RoomSelect.Click
SqlSelectCommand2.Parameters("@Room").Value =
INSRoom
SqlDataAdapter2.Fill(DsHousekeepitems1)
Dim sw As New System.IO.StringWriter()
DsHousekeepitems1.WriteXml(sw)
ViewState("DSHousekeepitems") = sw.ToString()
DataGrid1.DataBind()
End Sub

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

If IsPostBack Then
' SqlDataAdapter2.Fill(DsHousekeepitems1)
' Restore DSHousekeepitems1 data set from view
state.
Dim sr As New System.IO.StringReader(CStr
(ViewState("DSHousekeepitems")))
DsHousekeepitems1.ReadXml(sr)
DataGrid1.DataBind()
Else
SqlDataAdapter1.Fill(DsHousekeeping1)
RoomListBox.DataBind()
End If

Here is the error message I received when I run the form
(Line 305 was highlighted in red.):

Server Error in '/housekeeping' Application.
-----------------------------------------------------------
---------------------

Value cannot be null. Parameter name: s
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and where
it originated in the code.

Exception Details: System.ArgumentNullException: Value
cannot be null. Parameter name: s

Source Error:


Line 303: ' SqlDataAdapter2.Fill
(DsHousekeepitems1)
Line 304: ' Restore DSHousekeepitems1 data set
from view state.
Line 305: Dim sr As New System.IO.StringReader
(CStr(ViewState("DSHousekeepitems")))
Line 306: DsHousekeepitems1.ReadXml(sr)
Line 307: DataGrid1.DataBind()


Source File: F:\housekeeping\Housekeeping.aspx.vb Line:
305

Stack Trace:


[ArgumentNullException: Value cannot be null.
Parameter name: s]
System.IO.StringReader..ctor(String s) +78
housekeeping.WebForm1.Page_Load(Object sender,
EventArgs e) in F:\housekeeping\Housekeeping.aspx.vb:305
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724




-----------------------------------------------------------
---------------------
Version Information: Microsoft .NET Framework
Version:1.0.3705.288; ASP.NET Version:1.0.3705.288


Thanks in advance for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top