Click here to Skip to main content
15,867,835 members
Articles / Programming Languages / C#

Data Application Block for Firebird SQL

Rate me:
Please Sign up or sign in to vote.
3.97/5 (13 votes)
29 Mar 2006CPOL2 min read 57.8K   1.2K   41   9
Data Application Block for Firebird SQL intended to speed the development of applications

Sample Image - fb_burning_within2.gif

Introduction

The Firebird SQL data application block is intended to speed up development, and it should be used in conjunction with data layer classes in much the same way as Microsoft’s data block. The sample included with this article uses the embedded Firebird SQL database (included in the sample) to demonstrate the use of the application block without having to bother setting up a database.

Background

Firebird SQL data application block was inspired by the Microsoft Application Blocks. The block provides overloaded methods to query a Firebird database which returns a DataSet, DataTable, or an integer in the case of scalar database calls. An additional overload method takes an existing DataSet as a parameter and fills the results of a stored procedure sent as the parameter as well.

Using the Code

The block has one class called DBObject. The main class has four main overloaded methods to do the work. The methods need to be accessed after the class has been instantiated passing the connection string to its constructor. The following is a list of the overrun procedures and their purpose:

  • Overload RunProcedure() - Returns an integer indicating the return value of the stored procedure, and also returns the value of the RowsAffected aspect of the stored procedure that is returned by the ExecuteNonQuery method.
  • Overload RunProcedure() - Returns a FbDataReader containing the result of the stored procedure.
  • Overload RunProcedure() - Creates a DataSet by running the stored procedure and placing the results of the query/proc into the given table name.
  • Overload RunProcedure() - Takes an existing DataSet and fills the given table name with the results of the stored procedure.
C#
// First, we declare a string
// and assign our connection string to it. 
// In a production system, you would probably
// have this connection in a central repository 
// and have the DBObject get set it from within the class.
string myConnectionString = "User=SYSDBA;Password=masterkey;" + 
                            "Database=EMPLOYEE.FDB;ServerType = 1;"; 

// Instantiate the DBObject class
DBObject myDBObject = new DBObject(myConnectionString);

//Set parameter to the DBObject class. Note that to keep it simple, 
//the stored procedure in this case doesn’t take any parameters.
//There is an example with parameter s in the sample code for this article.
//Also, notice that I bind the dataset 
//the RunProcedure() method returns to a datagrid.
dataGridView1.DataSource = 
myDBObject.RunProcedure("ORG_CHART ", 
       new IDataParameter[] { }, "tblMyDataTable");
dataGridView1.AutoGenerateColumns = true;
this.dataGridView1.DataMember = "tblMyDataTable";

Points of Interest

Well, I hope that you find this code useful. I have used the data block in conjunction with the embedded version of Firebird SQL for many of my stand-alone applications. I especially like the fact that the applications work out of the box without the need for additional installations. It makes deployment a breeze since the database is included in the application itself, and all it takes is a couple of DLLs with a very small footprint.

History

  • 03/29/2006: First submitted to CodeProject

License

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


Written By
Web Developer
United States United States
Alex is the founder, President, Architect, of a one man development and consulting company (Avida, Corp of Miami, FL), and he is also a shameless self promoter. A deserter of the accounting profession, Alex is been developing/supporting windows and web applications for Fortune 500 and small companies as well since 2000.

His programming experience includes VB6, VB.NET, C#, ASP, ASP.NET, MSSQL 7/2000/2005, Firebird SQL 1.7. Alex has acquired expertise in Visual Studio, Reporting Services, SQL Server, and other stuff that I can’t remember right now.

In his spare time, he enjoys bicycling with his trusted Litespeed titanium racing bike which is his favorite material possession.

He goes anywhere and takes any challenge that the Technology field troughs at him, and sometimes he even wins. He can be more often found at code camps, user groups, the local Microsoft office’s cafeteria, or sleep in his couch.

Comments and Discussions

 
GeneralPlease Help Pin
softhut28-Jun-09 13:38
softhut28-Jun-09 13:38 

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.