Showing Data in a Firebird Database with a DataGridView

This demonstration uses one DataGridView component in an Oxygene WinForms application. It uses the same Firebird setup, CONTRIBUTIONS.FDB database and connection string as our Oxygene for .Net console example. The code follows a screenshot of the accessed data in the DataGridView. This C# page was helpful.

Screenshot of form

Screenshot of form

namespace WinForms_DB_Test;

interface

uses
  System.Windows.Forms,
  FirebirdSql.Data.FirebirdClient,
  System.Data;

type
  /// <summary>
  /// Summary description for MainForm.
  /// </summary>
  MainForm = partial class(System.Windows.Forms.Form)
  private
    connString: String;
    conn: FbConnection;
    da: FbDataAdapter;
    sql: String := 'SELECT Forename, Surname FROM Programmer';
    dt: DataTable;
    method MainForm_Load(sender: System.Object; e: System.EventArgs);
    
  protected
    method Dispose(disposing: Boolean); override;
  public
    constructor;
  end;

implementation

{$REGION Construction and Disposition}
constructor MainForm;
begin
  InitializeComponent();
  connString := 'User=student;' +
                'Password=pp4s;' +
                'Database=F:\\CONTRIBUTIONS.FDB;' +
                'DataSource=localhost;' +
                'Port=3050;';
  conn := new FbConnection(connString);
end;

method MainForm.Dispose(disposing: Boolean);
begin
  if disposing then begin
    if assigned(components) then
      components.Dispose();
  end;
  inherited Dispose(disposing);
end;
{$ENDREGION}

method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
begin
  da := new FbDataAdapter(sql, conn);
  dt := new DataTable();
  da.Fill(dt);
  dataGridView1.DataSource := dt;
end;

end.

Programming - a skill for life!

How to write programs in the Oxygene for .Net dialect of Pascal