Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:21:33+00:00 2026-06-08T14:21:33+00:00

This shouldnt be hard to answer but I am so desperate and confused. I

  • 0

This shouldnt be hard to answer but I am so desperate and confused. I made interface for executing read query from database

interface IDatabase
{
    DataTable ExecuteReaderCommand(IDbCommand command);
    IDbCommand GetNewCommand();
}

Next, I created two different classes implemetnig above interface.

class MysqlDatabase : IDatabase
{
    public DataTable ExecuteReaderCommand(MySqlCommand command)
    {
        DataTable dt = new DataTable();
        // ... read db
        return dt;
    }

    public MySqlCommand GetNewCommand()
    {
        cnn.Open();
        return cnn.CreateCommand();
    }
}

And

class SQLiteDatabase : IDatabase
{
String dbConnection;
    SQLiteConnection cnn;

    public DataTable ExecuteReaderCommand(SQLiteCommand command)
    {
        DataTable dt = new DataTable();
        // ... read db
        return dt;
    }

    public SQLiteCommand GetNewCommand()
    {
        cnn.Open();
        return cnn.CreateCommand();
    }
}

But I am getting error that these classes dont implement IDatabase interface:

 MysqlDatabase does not implement interface member 'Database.GetNewCommand()'
 MysqlDatabase.GetNewCommand() cannot implement 'Database.GetNewCommand()' because it does not have the matching return type of 'System.Data.IDbCommand'.

 SQLiteDatabase does not implement interface member Database.ExecuteReaderCommand(System.Data.IDbCommand)
 SQLiteDatabase does not implement interface member 'Database.GetNewCommand()'. SQLiteDatabase.GetNewCommand() cannot implement Database.GetNewCommand() because it does not have the matching return type of 'System.Data.IDbCommand'.

When I look on the SQLiteCommand and MySqlCommand they both implements IDbCommand.

How can I use these classes under common interface so I can easilly switch them?

I am very thankful for any answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:21:37+00:00Added an answer on June 8, 2026 at 2:21 pm

    When I look on the SQLiteCommand and MySqlCommand they both implements IDbCommand

    No they don’t. They claim they do, but they don’t actually provide the right methods. Look at IDatabase.GetNewCommand():

    IDbCommand GetNewCommand();
    

    and your implementation:

    public MySqlCommand GetNewCommand()
    {
        ... 
    }
    

    They’ve got different return types. Likewise your ExecuteReaderCommand method parameter is IDbCommand in IDatabase, but MySqlCommand in MysqlDatabase.

    Options:

    • Use explicit interface implementation for the “weakly typed” version, exposing the “strongly typed” versions on the concrete classes. This is what SqlCommand does in the .NET framework, for example.

    • Make IDatabase generic in the type of command it creates and uses:

      public interface IDatabase<TCommand> where TCommand : IDbCommand
      {
          DataTable ExecuteReaderCommand(TCommand command);
          TCommand GetNewCommand();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this shouldn't be that hard, but I couldn't find the answer on
This shouldn't be so hard but I just can't seem to get this to
I'm fairly new to Android, so this might have an obvious answer, but I
This really shouldn't be hard, I just can't figure out how to do it.
I'm still fairly new to Java, but I'm fairly sure this shouldn't happen. There's
Here's the thing: In my Qt4.6-Project, I use a SQLite-Database. This database shouldn't be
Shouldn't I be able to call this CoffeeScript method from within an erb template?
This shouldn't be hard to do. I'd expect Enterprise Manager to show a folder
This shouldn't be hard...I have a menu and some content wrapped in a centered,
I'm sure this shouldn't be so hard! I've been struggling with facebook's javascript :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.