?
Solved

Dispose dataset

Posted on 2007-10-16
7
Medium Priority
?
256 Views
Last Modified: 2013-12-17
I am using this function to dissociate object reference. In the same function i want to also dissociate (ie dispose Dataset if its passed) How can i achieve it in the same function ... Logic is like if  Dataset is passed, dispose it.  

public void  DissociateObject(System.Object Obj)
        {
            if (!Obj.Equals(null))
            {
                Obj = null;
            }
           
        }
0
Comment
Question by:dotnet0824
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 20087175
Hi,

try checking whether the object implements IDispose
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20087210
Overloaded function:

public void  DissociateObject(System.Object Obj)
{
    Obj = null;
}
   
   
private void DissociateObject(System.Data.DataSet Obj)
{
    Obj.Dispose();
    Obj  = null;
}
0
 

Author Comment

by:dotnet0824
ID: 20087258
Cant i check in the same function--Something like if obj is dataset then dispose... something of that sort
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 20087275

        public void  DissociateObject(System.Object Obj)
        {
            if (!Obj.Equals(null))
            {
                try
                {
                    ((IDisposable)Obj).Dispose();
                }
                catch
                {
                    //cast failed
                }
                Obj = null;
            }
           
        }
0
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 400 total points
ID: 20087327
Without generating expensive exceptions:
       

        public void DissociateObject(System.Object Obj)
        {
            if (!Obj.Equals(null))
            {
                if (Obj is DataSet)
                    ((DataSet)Obj).Dispose();
                Obj = null;
            }

        }
0
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 600 total points
ID: 20087451
or even more generally:

 public void DissociateObject(System.Object Obj)
        {
            if (!Obj.Equals(null))
            {
                if (Obj is IDisposable)
                    ((IDisposable)Obj).Dispose();
                Obj = null;
            }

        }
0
 

Author Comment

by:dotnet0824
ID: 20088815
Thanks a lot..
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question