DataTable in a ViewState

  • Thread starter Thread starter Pradeep
  • Start date Start date
P

Pradeep

Hi,

I am storing the DataTable in a ViewState.

ViewState("mydata") = dsRedemption.T_Redemption_Dtl

Then I am casting the ViewState into a DataTable variable.

Dim x As New DataTable
x = CType( ViewState("mydata"), DataTable)

This is giving me a error where it's not allowing me to Cast it. If i
directly see the data in the ViewState("mydata") it's perfectly fine. First
of all, is it advisable to store the DataTable in the ViewState ???

Any idea ???

Pradeep
 
First, I am a C# guy, and second, I have only done this with a DataSet, not
a DataTable, but in principle it should work equally well.

However, if your DataTable object is fairly large, it will make your page
load quite slowly (all of that data to construct your data table must be
piped across as part of the page's data). You could consider using a
Session variable so that it remains on the server. That will eat up server
memory, but it won't take the same performance hit on page loading.

Only other thing I noticed was this:DataTable object

Now, as I said, I am a C# guy, not a VB guy, but I don't think this should
cause the typecasting error. However, it does waste some time instantiating
a DataTable object that you are just going to replace with the next
statement. If I remember VB correctly, you may just want the following:
 
Back
Top