Search:
Namespaces
Discussions
.NET v1.1
Feedback
Persisting datasets using viewstates and xml
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngdatagridrepeaterdatalist' list
.
I am trying to use viewstates and xml to persist datasets instead of sessions, however, I get a NULL error when I try to read back the XML string.
Have I done something wrong ??? Here's part of my page_load() method
**************
if (ViewState["Hello"] == null) {
ds = new
DataSet
();
oleDa.Fill(ds, "customers");
string myXml = ds.GetXml();
//put xml from dataset into ViewState
ViewState["Hello"] = myXml;
} else {
//get xml back from ViewState
string vxml = ViewState["Hello"].ToString();
StringReader
sr = new
StringReader
(vxml);
//read in XML from stream
ds.ReadXml(sr);
}
if (!IsPostBack)
{
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
*******
Can someone help !!
CHEERS !!
Sum Pun
Reply to this message...
Alex Lowe
Have you checked out this article -
http://www.aspfree.com/authors/stephen
_rylander/Persist.aspx?
Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET
***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************
-----Original Message-----
From:
Click here to reveal e-mail address
[mailto:
Click here to reveal e-mail address
]
Sent: Sunday, August 11, 2002 7:17 AM
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] Persisting datasets using
viewstates and xml
I am trying to use viewstates and xml to persist datasets instead of
sessions, however, I get a NULL error when I try to read back the XML
string.
Have I done something wrong ??? Here's part of my page_load() method
**************
if (ViewState["Hello"] == null) {
ds = new
DataSet
();
oleDa.Fill(ds, "customers");
string myXml = ds.GetXml();
//put xml from dataset into ViewState
ViewState["Hello"] = myXml;
} else {
//get xml back from ViewState
string vxml = ViewState["Hello"].ToString();
StringReader
sr = new
StringReader
(vxml);
//read in XML from stream
ds.ReadXml(sr);
}
if (!IsPostBack)
{
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
*******
Can someone help !!
CHEERS !!
Sum Pun
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
=
YOUR ID |
http://www.aspfriends.com/aspfriends/aspngdatagridrepeaterdatalist.asp
=
JOIN/QUIT
Reply to this message...
Doug J. Nelson
In the code example you posted,=20
if (ViewState["Hello"] =3D=3D null) {=20
ds =3D new
DataSet
();=20
oleDa.Fill(ds, "customers");=20
string myXml =3D ds.GetXml();=20
//put xml from dataset into ViewState=20
ViewState["Hello"] =3D myXml;=20
} else {=20
//get xml back from ViewState=20
string vxml =3D ViewState["Hello"].ToString();=20
StringReader
sr =3D new
StringReader
(vxml); =20
//read in XML from stream=20
ds.ReadXml(sr);=20
}
Declare ds outside of the if statement when you get to the else
statement, ds is undeclared.
ds =3D new
DataSet
();
if(ViewState["Hello"] =3D=3D null)
{
oleDa.Fill(ds, "customers");=20
string myXml =3D ds.GetXml();=20
//put xml from dataset into ViewState=20
ViewState["Hello"] =3D myXml;=20
}
else
{
//get xml back from ViewState=20
string vxml =3D ViewState["Hello"].ToString();=20
StringReader
sr =3D new
StringReader
(vxml); =20
//read in XML from stream=20
ds.ReadXml(sr);=20
}
Doug Nelson
SynApp north
305 Arch St
Cloquet, MN 55720
(218) 878 - 2015=20
(218) 878 - 2019 fax
Reply to this message...
System.Data.DataSet
System.IO.StringReader
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com