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

High Performance ADO Database Library

1.80/5 (7 votes)
7 Feb 2018CPOL 6.8K   175  
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)