In general, I want to make a class that will import the DataTable into Access or MS SQL.
The class will have 1 method: Append, to which the DataTable will be fed into the input, and the method in turn will load the DataTable to the desired destination.
Of course, the Access internal logic of the Append can be very different, for example:
- In Access, you need to ensure that the file is not higher than 2GB, otherwise the database will break
- In MS SQL, you can use BulkCopy, and in Access you will need some kind of samopal.
Accordingly, the designers can vary greatly in parameters, for example:
- Connection strings will differ between the two types.
- In MS SQL, you can use or not use a transaction
- In Access, you can restore or not restore the database after each Append.
What is the best way to arrange all this?
UPD:
I have some suggestions on how this can be done, but I donβt know how true that is.
Make an interface:
public interface IApend { void Append(DataTable dt); } Implement it in 2 classrooms, each of which will contain its own import logic:
public class ImporterToSQL: IApend { //ΠΠ°ΠΊΠΈΠ΅-ΡΠΎ ΠΏΠΎΠ»Ρ public void Append(DataTable dt) { //ΠΠ°ΠΊΠ°Ρ-ΡΠΎ Π»ΠΎΠ³ΠΈΠΊΠ° } } public class ImporterAccess : IApend { //ΠΠ°ΠΊΠΈΠ΅-ΡΠΎ ΠΏΠΎΠ»Ρ public void Append(DataTable dt) { //ΠΠ°ΠΊΠ°Ρ-ΡΠΎ Π»ΠΎΠ³ΠΈΠΊΠ° } } And create such a class:
public class Importer { IApend Concrete; public Importer(IApend concrete) { Concrete = concrete; } static Importer ImporterToSQL(object v,object v2,object v3) { return new Importer(new ImporterToSQL(object v, object v2, object v3)); } static Importer ImporterToSQL(object v, object v2) { return new Importer(new ImporterToSQL(object v, object v2)); } static Importer ImporterToAccess(object v, object v2, object v3) { return new Importer(new ImporterAccess(object v, object v2, object v3))); } static Importer ImporterToAccess(object v, object v2) { return new Importer(new ImporterAccess(object v, object v2)); } public void Append(DataTable dt) { Concrete.Append(dt); } } How much is this true and how well will this approach work in terms of adding new functionality (for example, I was impatient to add import from SQL to Access)? Is it, like, called a class factory?