Filling the dataset with a table with same name as in an out of scope class

E

Earl

Lets say I have a SINGLE DataSet declared Public in a module to use across
all classes. What happens if, say, in Class1, I fill the DataSet with the
datatable "dtEmp", then later, after Class1 goes out of scope, in Class2, I
fill the DataSet and ALSO use the name for datatable as "dtEmp"? Do I get
the new resultset added to the existing resultset? Or because Class1 is no
longer in scope, does the datatable dtEmp get garbage collected?
 
M

Miha Markic [MVP C#]

Earl,

DataSet won't be gc-ed until you drop all references to it.
IOW while you have at least one living reference DataSet instance will be
there.
 
E

Earl

Thanks Miha. So I would still need to clear dtEmp in Class2 before a fill to
prevent dupe data? It seems that what you are saying is that the contents of
the project-wide DataSet would hold state regardless of whether the tables
within could be considered "in scope" within any particular class?

Miha Markic said:
Earl,

DataSet won't be gc-ed until you drop all references to it.
IOW while you have at least one living reference DataSet instance will be
there.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Earl said:
Lets say I have a SINGLE DataSet declared Public in a module to use across
all classes. What happens if, say, in Class1, I fill the DataSet with the
datatable "dtEmp", then later, after Class1 goes out of scope, in
Class2,
I
fill the DataSet and ALSO use the name for datatable as "dtEmp"? Do I get
the new resultset added to the existing resultset? Or because Class1 is no
longer in scope, does the datatable dtEmp get garbage collected?
 
M

Miha Markic [MVP C#]

Hi Earl,

I am not sure if I am following.
However, dataset is just a class that holds the data in tables. Like an
array of arrays, for example.
There is nothing special to it in this sense.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Earl said:
Thanks Miha. So I would still need to clear dtEmp in Class2 before a fill to
prevent dupe data? It seems that what you are saying is that the contents of
the project-wide DataSet would hold state regardless of whether the tables
within could be considered "in scope" within any particular class?

Miha Markic said:
Earl,

DataSet won't be gc-ed until you drop all references to it.
IOW while you have at least one living reference DataSet instance will be
there.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Earl said:
Lets say I have a SINGLE DataSet declared Public in a module to use across
all classes. What happens if, say, in Class1, I fill the DataSet with the
datatable "dtEmp", then later, after Class1 goes out of scope, in
Class2,
I
fill the DataSet and ALSO use the name for datatable as "dtEmp"? Do I get
the new resultset added to the existing resultset? Or because Class1
is
 
K

Kevin Yu [MSFT]

Hi Earl,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when a reference to an object is out of
scope, you need to fill it again with the same DataTable name. If there is
any misunderstanding, please feel free to let me know.

I agree with Miha's reply. The DataSet will be GC-ed when all references to
that object are dropped. If you have a DataSet member in an Class1 object,
when the reference to Class1 object goes out of scope, the reference is
dropped. It means that you cannot get to the DataSet object unless you have
other references to it. If you still hold some reference to the object, you
have to fill the DataTable with other names, because the original table is
still in it.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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

Top