dataset can not be shared across subs

  • Thread starter Thread starter nakhi
  • Start date Start date
N

nakhi

Hi,
I declared a dataset outside any subs, then I fill the dataset with a
tables in a Private Sub1, then I want to take the data out from the dataset
in Sub2.
like .
sub2()
datagrid.datasource=ds.tables("t").defautview
datagrid.databind()
end sub

but it goes wrong. if I show the tables the datagrid in the sub where the
dataset is fill with SQLdataAdapter, it is OK.

I remmebered dataset is in memory, can I shared the dataset in different
Subs?

thanx.
Nakhi
Lijiang,Yunnan,China
 
remember the web is stateless so as soon as you post back from the server
your data is gone which is why it doesn't work outside of the sub. what you
will need to do is hold the data somewhere and get it when you need to
consider
Session["STORE"] = ds from sub 1
in sub 2
DataSet ds = new DataSet();
if(Session["STORE"] != null)
ds = (DataSet)Session["STORE"];
 
thanx,I filled the dataset in Sub Page_load(), so it is run in every
request, and I can share the dataset in any subs.

Nakhi

Alvin Bruney said:
remember the web is stateless so as soon as you post back from the server
your data is gone which is why it doesn't work outside of the sub. what you
will need to do is hold the data somewhere and get it when you need to
consider
Session["STORE"] = ds from sub 1
in sub 2
DataSet ds = new DataSet();
if(Session["STORE"] != null)
ds = (DataSet)Session["STORE"];
nakhi said:
Hi,
I declared a dataset outside any subs, then I fill the dataset with a
tables in a Private Sub1, then I want to take the data out from the dataset
in Sub2.
like .
sub2()
datagrid.datasource=ds.tables("t").defautview
datagrid.databind()
end sub

but it goes wrong. if I show the tables the datagrid in the sub where the
dataset is fill with SQLdataAdapter, it is OK.

I remmebered dataset is in memory, can I shared the dataset in different
Subs?

thanx.
Nakhi
Lijiang,Yunnan,China
 
Back
Top