My idea is to use system. Data. Common; without directly specifying data to provideProgramCreate the dbconnection class and dbcommand by passing parameters.
CodeIt is also very simple. It is almost the same as it is:
Type temptype = type. GetType ("system. Data." + typename + ", system. Data, version = 2.0.0.0, culture = neutral, publickeytoken = b77a5c561934e089 ")
Object tempobj = activator. createinstance (temptype );
_ Connetion = (dbconnection) tempobj;
Typename is the input parameter, such as oledb. oledbconnection,
_ Connetion is an empty dbconnection, which can be output as a property in the class.
In this way, as long as typename is controlled, the database can be switched online. We can put typename and connection fields into XML or another database (I select access, in this way, you only need to perform operations on the database in the management background to switch the main database of the program.
All of the above are passed in vs2005. Ms SQL Server2000 Access 2003 Oracle 9i tested
Hope to give some inspiration to some friends