Connecting to InterBase from Visual Studio

From InterBase
Jump to: navigation, search

Go Up to Main Page

InterBase currently supports an ADO.Net driver that works with InterBase XE, XE3, and XE7 with both 32-bit and 64-bit support.

This topic covers the basic information for connecting to InterBase from Visual Studio:

Prerequisites

You will need the following:

  • .Net 2.0 SDK with update
  • Microsoft Visual Studio 2005 or above
  • InterBase XE or above

Installation Instructions

For instructions on running the ADO.Net 2.0 installer, click here.

Usage Instructions

  1. Start Visual Studio 2005/2008.
  2. File new C# Windows application.
  3. Project - Add Reference and add the AdoDbxClient.dll, DbxCommonDriver, DBXInterBaseDriver to your project.
  4. Add a DataGridView component to your Windows form.
  5. The sample code below fills a DataGridView component with the contents of the employee table of the employee.gdb sample InterBase database:


Example Code

This sample code was used with InterBase XE7 and Visual Studio 2013 Ultimate.

>>>
USING System;
USING System.Collections.Generic;
USING System.ComponentModel;
USING System.DATA;
USING System.Drawing;
USING System.Text;
USING System.Windows.Forms;
USING Borland.DATA;
USING Borland.DATA.Units;
USING System.DATA.SqlClient;
USING System.DATA.Common;
namespace IBXEApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ReadData(getConnection());
        }
        public DbConnection getConnection()
        {
           // DbProviderFactory factory = DbProviderFactories.GetFactory
             //            ("Borland.Data.AdoDbxClient");
            DbConnection c = NEW TAdoDbx{{Product}}Connection();
            //DbConnection c = factory.CreateConnection();
            c.ConnectionString = "Database=C:\\Embarcadero\\{{Product}}\\examples\\database\\employee.gdb;User_Name=sysdba;Password=masterkey";
            RETURN c;
        }
        public void ReadData(DbConnection conn)
        {
            string SQL = "select * from employee";
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandText = SQL;
            conn.OPEN();
            DbDataReader myreader = cmd.ExecuteReader();
            dataGridView1.DataSource = myreader;
            DataSet ds = NEW DataSet();
            DataTable dt = NEW DataTable("employee");
            ds.TABLES.ADD(dt);
            ds.LOAD(myreader, LoadOption.PreserveChanges, ds.TABLES[0]);
            dataGridView1.DataSource = ds.TABLES[0];
            myreader.Close();
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
   }
}
<<<
Personal tools
Previous Releases:
In other languages