Problem with lost Dataset

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
I have a small problem with a dataset that I keep losing (eg =nothing). In my page_load event I connect to a database, create a (public) dataset, and then bind the dataset to the datagrid.

What I want to do now is add another row to the datagrid (but not commit to the database yet). So I'm trying to find my public dataset to add another row, and its always nothing!

Am I missing something awfully fundamental here? I'm primaryly a windows programmer... so its possible I'm being a dunce...


The only other way I can think of doing this, is to convert the dataset into xml and chuck it into a hidden input, and then extract it, modify it, and put it back when I need to go to the server...

What do you guys think about this idea?
 
You can alternatively store the DataSet in a session variable:

Session["saveMyDataSet"] = theDataSet;

and later retrieve it by

theDataSet = (DataSet) Session["saveMyDataSet"];

This avoids making the viewstate larger (larger pages to transport back and forth to the browser) but at the cost of forcing the server to maintain it.

The important thing to realize is that on every postback, the page is being recreated from scratch so you have to figure out some way of saving any information you need to preserve. Viewstate and session variables are two ways you can do it.
 
Back
Top