views:

1327

answers:

7

Hi, I am sorry if I am asking something stupid but I am completely a newbie in C# and ASP.NET. I am having an error in my code and I don't understand it. I am working on Visual Studio 2008.

In this line of code:

public class SQLFAQProvider : DBFAQProvider

I am getting this error:

Moby.Commerce.DataAccess.FAQ.SQLFAQProvider'does not implement inherited abstract member Moby.Commerce.DataAccess.FAQDBFAQProvider.DeleteFAQbyID(int)'

When I go to DBFAQProvider the error is in this line of code:

public abstract DBFAQ DeleteFAQbyID(int fAQID);

What should i change to correct it???

+1  A: 

Your subclass (SQLFAQProvider) must provide implementation code for the method DeleteFAQbyID because the parent class (DBFAQProvider) did not.

Matthew Sposato
+1  A: 

First thought would be implement the abstract member in the inherited class ala:

public class SQLFAQProvider : DBFAQProvider
{
    public override DBFAQ DeleteFAQbyID(int fAQID)
    {
        //TODO: Real Code
        return null;
    }
}
Quintin Robinson
+11  A: 

Implement the DeleteFAQbyID method in your derived class:

public override DBFAQ DeleteFAQbyID(int fAQID)
{
    // Put your code here
}

The point of an abstract method is to say (in the abstract base class), "I want to make sure that this method is available in every concrete class deriving from me" - it's up to you to provide the implementation. It's a bit like a method in an interface.

Jon Skeet
+2  A: 

When a class inherits from an abstract class it must implement all abstract methods defined by said class. This is the class interface, the abstract methods can be thought of as pure virtual functions, i.e., functions that must be implemented by descended classes but do not make sense to be implemented in the base class.

Ed Swangren
+4  A: 

Your subclass needs to explicitly implement that particular method.

If you have no idea how to do it, then at least do:

public override  DBFAQ DeleteFAQbyID(int fAQID)
{
    throw NotImplementedException("This isn't done yet");
}
chris
+1  A: 

Because your SQLFAQProvider class isn't abstract, it has to implement every abstract method that it inherits.

To fix this, implement the DeleteFAQbyID method in SQLFAQProvider, like this:

public override DBFAQ DeleteFAQbyID(int fAQID) {
    //Do something
}

Alternatively, you could make your SQLFAQProvider class abstract by changing its declaration to public abstract class SQLFAQProvider.

SLaks
+2  A: 

When you inherit from a class in C#, you are required to implement all methods marked as abstract unless your class is itself marked as abstract. Abstract classes are ones that cannot be directly instantiated at runtime because they don't fully implement all of the required methods that the base class(es) say must exist.

Abstract methods are a mechanism that allows a class to indicate that a particular method must "eventually" exist - without having to provide an implementation at that point. You typically use abstract classes when you cannot or don't want to dictate what a particular implementation should do, but you need to pre-define a method that you will eventually rely on.

To fix your problem either mark your class as abstract (with the expectation that another level of inheritance will fill in the missing pieces) or implement DeleteFAQbyId() in your class:

public DBFAQ DeleteFAQbyID(int fAQID)
{
    // write appropriate implementation here or:
    throw new NotImplementedException();
    // or possibly NotSupportedException() if the operation should can't ever be supported.
}
LBushkin