I have the following code, this class where I define the interface
namespace classBD.clases.connexiones
{
public interface IConexion
{
void OpenConection();
void CloseConnection();
void ExecuteQueries(string Query);
object ShowDataInGridView(string Query);
DbDataReader DataReader(string Query);
Boolean Ejecutar(string query, Dictionary<string,string> parametros);
}
public class ConnectionFactory
{
public static IConexion GetConnection()
{
string valconfig = "sqlite";
if(valconfig == "sqlite")
return new conexionSQlite();
else
return new conexionSQLServer();
}
}
}
Then I have an implementation for sqlServer and another for Sqllite (I put only a piece of code)
namespace classBD.clases.connexiones
{
public class conexionSQlite : IConexion
{
SQLiteConnection conexionSQLite;
public void OpenConection()
{
conexionSQLite = new SQLiteConnection(ConnectionString);
try
{
conexionSQLite.Open();
}
catch (Exception ex)
{
string error = ex.Message;
}
}
public void CloseConnection()
{
conexionSQLite.Close();
}
...
...
public Boolean Ejecutar(string query, Dictionary<string, string> parametros)
{
Boolean retorno = true;
this.OpenConection();
SQLiteCommand Comando = new SQLiteCommand(query, conexionSQLite);
foreach (var p in parametros)
{
Comando.Parameters.Add(p);
}
try
{
Comando.ExecuteNonQuery();
}
catch
{
retorno = false;
}
return retorno;
}
}
}
Then I have something similar for sql server.
When executing this code the error I receive is this
Thanks