Visual Studio .NET 2002.NET 1.0DBAVisual Studio .NET 2003.NET 1.1Visual Studio 2005.NET 2.0中级开发Visual StudioWindows.NETC#
Firebird SQL 的数据应用程序块
用于 Firebird SQL 的数据应用程序块,旨在加快应用程序的开发速度。
引言
Firebird SQL 数据应用块旨在加速开发,它应该与数据层类结合使用,就像 Microsoft 的数据块一样。 本文附带的示例使用嵌入式 Firebird SQL 数据库(包含在示例中)来演示应用程序块的使用,而无需费心设置数据库。
背景
Firebird SQL 数据应用块的灵感来自 Microsoft 应用程序块。 该块提供了重载方法来查询 Firebird 数据库,该数据库返回一个 DataSet
、DataTable
或标量数据库调用的整数。 另外一个重载方法将现有的 DataSet
作为参数,并填充作为参数发送的存储过程的结果。
Using the Code
该块有一个名为 DBObject
的类。 主类有四个主要重载方法来完成工作。 这些方法需要在类被实例化后访问,并将连接字符串传递给其构造函数。 下面是溢出过程及其目的的列表
- 重载
RunProcedure()
- 返回一个整数,指示存储过程的返回值,并且还返回由ExecuteNonQuery
方法返回的存储过程的RowsAffected
方面的数值。 - 重载
RunProcedure()
- 返回一个包含存储过程结果的FbDataReader
。 - 重载
RunProcedure()
- 通过运行存储过程并将查询/过程的结果放入给定的表名来创建DataSet
。 - 重载
RunProcedure()
- 接受现有的DataSet
并使用存储过程的结果填充给定的表名。
// 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";
关注点
好吧,我希望您觉得这段代码有用。 我已经将数据块与嵌入式版本的 Firebird SQL 结合用于我的许多独立应用程序。 我特别喜欢这些应用程序开箱即用的事实,而无需额外安装。 它使部署变得轻而易举,因为数据库包含在应用程序本身中,并且只需要几个 DLL,而且占用空间很小。
历史
- 2006 年 3 月 29 日:首次提交到 CodeProject