Click here to Skip to main content
15,908,444 members
Articles / Programming Languages / C#
Article

Database manager

Rate me:
Please Sign up or sign in to vote.
1.62/5 (11 votes)
19 Jan 20071 min read 38.6K   757   21   9
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


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Momano13-Jul-10 4:55
Momano13-Jul-10 4:55 
Generaldiploma thesis Pin
cccp1424-Feb-10 5:38
cccp1424-Feb-10 5:38 
Hi you dont have information about license and I didnt find it in the code either...
wanna ask whether I can use your project in my diploma thesis.... its an educational game application for children to learn while they play Smile | :)
Excuse my bad English OSmile | :)
Questionhow to use update method to insert Pin
Member 27434153-Jan-08 1:15
Member 27434153-Jan-08 1:15 
GeneralUpdate method does not work... Pin
Cabbi22-Jan-07 3:25
Cabbi22-Jan-07 3:25 
GeneralRe: Update method does not work... Pin
NaNg1524122-Jan-07 6:33
NaNg1524122-Jan-07 6:33 
NewsRe: Update method does not work... Pin
NaNg1524123-Jan-07 6:56
NaNg1524123-Jan-07 6:56 
GeneralGood Idea but... Pin
Cabbi19-Jan-07 3:45
Cabbi19-Jan-07 3:45 
GeneralRe: Good Idea but... Pin
NaNg1524119-Jan-07 20:04
NaNg1524119-Jan-07 20:04 
NewsRe: Good Idea but... Pin
NaNg1524120-Jan-07 4:32
NaNg1524120-Jan-07 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.