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.