C# Firebird Demonstration (.Net)

We give detailed instructions in the database tutorial for getting started with Firebird and for creating and populating the CONTRIBUTIONS Firebird database. This C# code accesses a copy of CONTRIBUTIONS.FDB in the C:\Working folder.

For this program you need to set up access to Firebird with the Firebird ADO.Net Data Provider.

Follow these instructions for the SharpDevelop IDE.

  1. Right-click on References then left-click on Manage Packages... as shown in the screenshot:
    Manage Packages

    Manage Packages

  2. Enter into the NuGet search text box FirebirdSql.Data.FirebirdClient as shown below then click on the search icon.
    NuGet Search

    NuGet Search

  3. Click on Firebird ADO.Net Data Provider then on the Add button that appears when you make the selection.

Follow these instructions for a RemObjects C# solution in Visual Studio.

  1. If you do not have the Package Manager among your Visual Studio tools, you can install it from the NuGet home page.
  2. View the Package Manager prompt by selecting menu item Tools > NuGet Package Manager > Package Manager Console.
  3. Type the command Install-Package FirebirdSql.Data.FirebirdClient at the NuGet Package Manager prompt.

The Code

using System;
using FirebirdSql;
using FirebirdSql.Data;
using FirebirdSql.Data.FirebirdClient;

namespace fb_test_dot_net
{
  static class Program
  {
    public static void Main(string[] args)
    {
      string connString = "User=student;" +
                          "Password=pp4s;" +
                          "Database=C:\\Working\\CONTRIBUTIONS.FDB;" +
                          "DataSource=localhost;" +
                          "Port=3050;";
      FbConnection conn = new FbConnection(connString);
      conn.Open();
      String sql = "SELECT Forename FROM Programmer ORDER BY Forename";
      FbCommand com = new FbCommand(sql, conn);
      FbDataReader dr = com.ExecuteReader();
      while (dr.Read()) 
      {
        Console.WriteLine(dr.GetString(0));
      }
     dr.Close();
     conn.Close();
     Console.ReadLine();
    }
  }
}

Programming - a skill for life!

C# Demonstrations of I/O, arrays, methods, classes, loops, enums, pointers, file handling, Firebird databases, LINQ and drawing on a form