I need a class to handle all databases easily. For example using ado and sql we have SqlConnec开发者_开发问答tion but it's not generic and for another database types you have to use other classes.
I would like a DatabaseConnection type of object to easily let me connect to various type of databases and let me run queries on database.
OleDB can work. But this has a performance hit.
Instead go with the "IDb" interfaces. I believe they are in namespace System.Data.Common. Using these interfaces gives the best of both worlds. Your code is database independent, but still gets the performance of a database specific dataProvider. The Idb interfaces also allow OleDB to be used if you need that. The actual provider to use will be configured in your Web.config or App.config file.
ALWAYS (yes always) use the IDb interfaces.
Object oriented programming 101. Program to an interface, not an implementation.
OleDbConnection in the System.Data.OleDb
namesapce
I would recommend that you use an abstract factory with a Data Access Object pattern. This should suit your needs nicely. See http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html for a full tutorial on the pattern. While the website speaks in terms of java the pattern can be used in c# as well.
精彩评论