Link to home
Start Free TrialLog in
Avatar of dotnet0824
dotnet0824

asked on

Dispose dataset

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;
            }
           
        }
Avatar of Babycorn-Starfish
Babycorn-Starfish
Flag of United States of America image

Hi,

try checking whether the object implements IDispose
Overloaded function:

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

ASKER

Cant i check in the same function--Something like if obj is dataset then dispose... something of that sort

        public void  DissociateObject(System.Object Obj)
        {
            if (!Obj.Equals(null))
            {
                try
                {
                    ((IDisposable)Obj).Dispose();
                }
                catch
                {
                    //cast failed
                }
                Obj = null;
            }
           
        }
SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot..