Click here to Skip to main content
15,891,657 members
Articles / Programming Languages / C#
Tip/Trick

High Performance ADO Database Library

Rate me:
Please Sign up or sign in to vote.
1.80/5 (7 votes)
7 Feb 2018CPOL 6.4K   168   3   2
A high-performance and well tested C# ADO library for connecting and querying a SQL database

Introduction

This C# class library can be used to simplify database connection code used by your application. It provides many high performance and well tested methods that are commonly used when interacting with databases.

Includes commonly used database methods such as:

  • Open()
  • Close()
  • TestConnection()
  • Execute()
  • Fetch()
  • UpdateData()
  • InsertData()
  • InsertAutonumRecord()
  • DeleteData()
  • ListTables()

Background

As a senior developer for over 15 years, I have found that high performance reusable code is highly effective when creating applications. There is no need to start from scratch for many well known technologies. I have used this library many times, and it has proven to be effective and saves time. Enjoy!

Using the Code

The below sample code can be used in your application to open a database connection and perform some basic operations.

Make sure you add a project reference to the "ADODBLib" class library project included in this article.

C#
// add a project reference in your application to ADODBLib
// use the DBConnection class to manage all db interaction
ADODBLib.DBConnection conn = new ADODBLib.DBConnection
("Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password = myPassword; ");

// open a database connection.
// returns null if successful.
string result = conn.Open();
if (result == null)
{
    System.Diagnostics.Debug.WriteLine("db open succeeded");
    
    // query the db to return some records.
    // returns a DataTable with DataRows if successful.
    System.Data.DataTable fetch = conn.Fetch("select * from table1");
    if (fetch != null)
    {
        System.Diagnostics.Debug.WriteLine("db fetch succeeded. row count = " + fetch.Rows.Count);
    }
    else
    {
        System.Diagnostics.Debug.WriteLine("db fetch succeeded");
    }
    
    // execute a SQL statement.
    // returns null if successful.
    string execute = conn.Execute("delete from table1 where id = 1");
    if (execute == null)
    {
        System.Diagnostics.Debug.WriteLine("db execute succeeded");
    }
    else
    {
        System.Diagnostics.Debug.WriteLine("db execute failed. " + result);
    }
    
    // closes the db connection.
    // must close after database connection is no longer needed.
    conn.Close();
}
else
{
    System.Diagnostics.Debug.WriteLine("db open failed. " + result);
}

History

  • ADODBLib version 10.0.0.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Self
United States United States
I am a professional software developer, specializing in Microsoft development technologies, with over 18 years experience. I write software and manage software development teams at work, but I also maintain my own apps for personal use.

Comments and Discussions

 
QuestionSimple and Easy Pin
Mark J8-Feb-18 12:15
Mark J8-Feb-18 12:15 
QuestionDapper Pin
Sacha Barber8-Feb-18 4:22
Sacha Barber8-Feb-18 4:22 

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.