IDispose problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lasse Edsvik

    IDispose problem

    Hello

    I'm trying to create a class that uses northwind database and use the
    IDisposable interface thingy :)

    Can someone explain why I get:

    Error 1 'Procent.DataJo x.Northwind' does not implement interface member
    'System.IDispos able.Dispose()' C:\Documents and Settings\Admini strator\My
    Documents\Visua l Studio 2005\Projects\D ataJox\DataJox\ Class1.cs 10 18
    Procent.DataJox

    and (on the using(Open()) row):

    Warning 2 Possible mistaken empty statement C:\Documents and
    Settings\Admini strator\My Documents\Visua l Studio
    2005\Projects\D ataJox\DataJox\ Class1.cs 16 26 Procent.DataJox


    using System;

    using System.Collecti ons.Generic;

    using System.Text;

    using System.Data;

    using System.Componen tModel;

    using System.Data.Sql Client;

    namespace Procent.DataJox

    {

    public class Northwind : IDisposable

    {

    private bool disposed = false;


    public DataSet GetAllCustomers ()

    {

    using(Open());

    // some code here to get data

    }

    private void Open()

    {

    string connstr =
    "server=localho st;database=nor thwind;trusted_ connection=true ;";

    SqlConnection dbconn = new SqlConnection(c onnstr);

    }

    private void Dispose()

    {

    Dispose(true);


    }

    private void Dispose(bool disposing)

    {

    if (!this.disposed )

    {

    if (disposing)

    {

    component.Dispo se();

    }

    CloseHandle(han dle);

    handle = IntPtr.Zero;

    }

    disposed = true;

    }

    ~Northwind()

    {

    Dispose(false);

    }

    }


    }


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: IDispose problem

    Hi,

    Why you need to implement IDIsposable?

    The error is saying clearly your problem, the Dispose method is not
    implemented, you declared it as private when it has to be public ( the one
    with no parameters)

    if you are using VS when you declare the class and set what interfaces you
    are going to implement the IDE will give you an option to expand the methods
    you need to implement, use it when possible


    cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation



    "Lasse Edsvik" <lasse@nospam.c om> wrote in message
    news:uiVZsPG5FH A.1028@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hello
    >
    > I'm trying to create a class that uses northwind database and use the
    > IDisposable interface thingy :)
    >
    > Can someone explain why I get:
    >
    > Error 1 'Procent.DataJo x.Northwind' does not implement interface member
    > 'System.IDispos able.Dispose()' C:\Documents and Settings\Admini strator\My
    > Documents\Visua l Studio 2005\Projects\D ataJox\DataJox\ Class1.cs 10 18
    > Procent.DataJox
    >
    > and (on the using(Open()) row):
    >
    > Warning 2 Possible mistaken empty statement C:\Documents and
    > Settings\Admini strator\My Documents\Visua l Studio
    > 2005\Projects\D ataJox\DataJox\ Class1.cs 16 26 Procent.DataJox
    >
    >
    > using System;
    >
    > using System.Collecti ons.Generic;
    >
    > using System.Text;
    >
    > using System.Data;
    >
    > using System.Componen tModel;
    >
    > using System.Data.Sql Client;
    >
    > namespace Procent.DataJox
    >
    > {
    >
    > public class Northwind : IDisposable
    >
    > {
    >
    > private bool disposed = false;
    >
    >
    > public DataSet GetAllCustomers ()
    >
    > {
    >
    > using(Open());
    >
    > // some code here to get data
    >
    > }
    >
    > private void Open()
    >
    > {
    >
    > string connstr =
    > "server=localho st;database=nor thwind;trusted_ connection=true ;";
    >
    > SqlConnection dbconn = new SqlConnection(c onnstr);
    >
    > }
    >
    > private void Dispose()
    >
    > {
    >
    > Dispose(true);
    >
    >
    > }
    >
    > private void Dispose(bool disposing)
    >
    > {
    >
    > if (!this.disposed )
    >
    > {
    >
    > if (disposing)
    >
    > {
    >
    > component.Dispo se();
    >
    > }
    >
    > CloseHandle(han dle);
    >
    > handle = IntPtr.Zero;
    >
    > }
    >
    > disposed = true;
    >
    > }
    >
    > ~Northwind()
    >
    > {
    >
    > Dispose(false);
    >
    > }
    >
    > }
    >
    >
    > }
    >
    >[/color]


    Comment

    Working...