Question

Can a datareader be stored in a viewstate?

What data can be stored in viewstate?

Was it helpful?

Solution

Any data [serializable] that you need to access during postbacks can be stored in a ViewState.

A DataReader cannot be serialised because is is based on Connected model. So it can't be stored in ViewState.

Also storing huge datatables in ViewState is not advisable. Return only necessary data that you need to show in the current context.

OTHER TIPS

I guess DataReader can't be stored. Just like xpathiterator can't.

The thing is - class must be serializable to store it in viewstate.


Quick googling gave me this:

A DataReader is not serializable as XML. If you want to store a result set in ViewState, use a DataTable or DataSet.

you can store in view state anything that is SERIALIZABLE

so no, you can't

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top