net 开发 Firebird数据库应用入门小例

http://blog.csdn.net/dujunli/archive/2004/10/20/144577.aspx

一、先到http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_download_dotnet 下载 Firebird .Net Data Provider ,我下载的是Data Provider for .NET Framework 1.1这个版本,这里还有文档:Documentation
二、运行FirebirdNETProvider-1.6.3-NET1.1.exe 执行安装程序
三、打开vs.net 2003,新建windows应用
四、添加Firebird .Net Data到vs2003.net工具箱,见下图:
net 开发 Firebird数据库应用入门小例
net 开发 Firebird数据库应用入门小例
五、放一个FbConnection到应用中,并修改相关属性:
        先修改ConnectionString,点右边的属性编辑窗口,注意ServerType,本驱动支持Super/Classic Servert 和Embedded Server两种情况
net 开发 Firebird数据库应用入门小例net 开发 Firebird数据库应用入门小例
六、
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace testfb
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private FirebirdSql.Data.Firebird.FbConnection DBConn;
  private FirebirdSql.Data.Firebird.FbCommand fbCommand1;
  private FirebirdSql.Data.Firebird.FbDataAdapter fbDataAdapter1;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.DataGrid dataGrid1;
  private System.Data.DataSet dataSet1;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
   this.DBConn = new FirebirdSql.Data.Firebird.FbConnection();
   this.fbCommand1 = new FirebirdSql.Data.Firebird.FbCommand();
   this.fbDataAdapter1 = new FirebirdSql.Data.Firebird.FbDataAdapter();
   this.button1 = new System.Windows.Forms.Button();
   this.dataGrid1 = new System.Windows.Forms.DataGrid();
   this.dataSet1 = new System.Data.DataSet();
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
   ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
   this.SuspendLayout();
   //
   // DBConn
   //
   this.DBConn.ConnectionString = ((string)(configurationAppSettings.GetValue("DBConn.ConnectionString", typeof(string))));
   //
   // fbCommand1
   //
   this.fbCommand1.CommandText = "select first 10 skip 10 * from email";
   this.fbCommand1.Connection = this.DBConn;
   //
   // fbDataAdapter1
   //
   this.fbDataAdapter1.SelectCommand = this.fbCommand1;
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(32, 272);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "button1";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // dataGrid1
   //
   this.dataGrid1.DataMember = "";
   this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
   this.dataGrid1.Location = new System.Drawing.Point(16, 8);
   this.dataGrid1.Name = "dataGrid1";
   this.dataGrid1.Size = new System.Drawing.Size(440, 256);
   this.dataGrid1.TabIndex = 1;
   //
   // dataSet1
   //
   this.dataSet1.DataSetName = "NewDataSet";
   this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(472, 318);
   this.Controls.Add(this.dataGrid1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
   ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   this.DBConn.Open();
   this.fbDataAdapter1.Fill(this.dataSet1,"EMAIL");
   this.DBConn.Close();
   this.dataGrid1.DataSource = this.dataSet1.Tables[0].DefaultView;
  }
 }
}


你可能感兴趣的:(数据库)