dataset can not be shared across subs

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
 
A

Alvin Bruney

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"];
 
N

nakhi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top