Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Database manager

1.62/5 (11 votes)
19 Jan 20071 min read 1   762  
A usefull tool to control the database, easy to use and easy to control.

Introduction

Using the DbConnection, DbDataAdapter and DbCommand makes the code very long and not easy for the eyes.

This class will make it easy to work with arround DataBases, and will shorten the code in atleast 4 more lines for every command.

A simple example

C#
System.Data.DbManager DbMgr = new System.Data.DbManager("System.Data.OleDb", connstring);
DataTable dtUsers = DbMgr.Retrieve("Select * From tblUsers");
String TopUser = DbMgr.Scalar("Select Top 1 UserName From tblUsers").ToString();
DbMgr.Execute("Delete * From tblUsers");

This will create a new DbManager instense with the OleDb data type, return the tblUsers table, return to top first username and will delete all from tblUsers table.

This is done in here in 4 lines where without it, it would have taken atleast 10 lines.

How it works

In every command that is needed to be done by the class, it opens and closes the connection, this to make sure that the connection will stay closed at all times, so that other connections can be made to that source.

To get a more information on how it works you are welcomed to look at the source code.

Creating your own manager

The usage of this class could be done in alot of the data types such as OleDb, Odbc, SqlClient etc., but if you have a problem with it, you are welcomed to create your own manager class, and can derive from the IDbManager interface.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here