public class DatabaseGateway
{
public DataTable QueryForDataTable(string expression)
{
using (IDatabaseConnection connection = new DatabaseConnection())
{
DataTable table = new DataTable();
using (IDataReader reader = connection.CreateCommandFor(expression).ExecuteReader())
{
table.Load(reader);
}
return table;
}
}
}
public class DatabaseConnection : IDatabaseConnection
{
public IDbCommand CreateCommandFor(string dynamicSqlExpression)
{
IDbCommand command = underlyingConnection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = dynamicSqlExpression;
return command;
}
public void Dispose()
{
underlyingConnection.Close();
underlyingConnection.Dispose();
underlyingConnection = null;
}
// ...
}
You need to create an account or log in to post comments to this site.