Saving and Retrieving a Dataset to and from View State.
To save:
sqlDataAdapter1.Fill(dSet);
System.IO.StringWriter sw = new System.IO.StringWriter();
// Write the DataSet to the ViewState property.
dSet.WriteXml(sw);
ViewState["dSet"] = sw.ToString();
To retrieve:
if (Page.IsPostBack)
{
System.IO.StringReader sr =
new System.IO.StringReader((string)(ViewState["dSet"]));
dSet.ReadXml(sr);
}
Without saving and retrieving from and to viewstate in asp.net, using dataset becomes inefficient completely. I’ve been seeked these methods to load information database only once if not already loaded and finally got it.






hi,
i’m have some problem with this system.io.reader,
can u help me with the code?
thank you.
note::
i always getting value cannot be null. parameter name s when executing the above statement..
Have you tried to convert DataSet’s xml to string and store it to ViewState? For me, it works fine.
thanx a lot
this is what i was looking for
thanx again