Data Application Block for Firebird SQL
Data Application Block for Firebird SQL intended to speed the development of applications
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 theRowsAffected
aspect of the stored procedure that is returned by theExecuteNonQuery
method. - Overload
RunProcedure()
- Returns aFbDataReader
containing the result of the stored procedure. - Overload
RunProcedure()
- Creates aDataSet
by running the stored procedure and placing the results of the query/proc into the given table name. - Overload
RunProcedure()
- Takes an existingDataSet
and fills the given table name with the results of the stored procedure.
// 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