Build a Simple VCL Application for Access データ

How to build a simple VCL Application to view Access データ in RAD Studio using the CData ODBC Driver for Access.

最終更新日:2023-06-12

Embarcadero RAD Studio provides a development environment for Delphi and C++Builder applications. With the CData ODBC Driver for Access, you gain access to live Access データ within RAD Studio, abstracting the data into tables, views, and stored procedures that can be used to retrieve and update Access データ. This article will walk through connecting to Access and creating a simple VCL application with the Form Designer.

Create a Connection to Access データ

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

Access接続の設定方法

ローカルファイルへの接続設定

ローカル環境からAccess への接続は非常にシンプルです。ConnectionTypeLocal に設定することで、CRUD 操作(SELECT、INSERT、UPDATE、DELETE)をすべて実行できます。接続にはDataSource プロパティに以下のようなAcces sデータベースファイルのフルパスを指定します。

C:\Users\Public\Documents\MyDatabase.accdb

詳細な接続手順については、ヘルプドキュメントの「はじめに」セクションをご参照ください。

クラウドストレージ上のAccess ファイルへの接続設定

各種クラウドストレージに保存されているAccess ファイルへのアクセスにも対応しています。ただし、クラウド上のファイルに対するデータ操作は、INSERT、UPDATE、DELETE に制限されますのでご注意ください。

S3、Google Driver、OneDrive など、各種クラウドストレージ内のAccess ファイルへの接続方法はこちらの記事をご確認ください。

クラウド上のファイルを更新したい場合は、以下の手順で実施いただけます。

  1. 対応するCData ドライバーを利用し、クラウドサービスからAccess ファイルをダウンロード
  2. Access ドライバーを使用して、ローカル環境でファイルを編集
  3. クラウドサービス用ドライバーのストアドプロシージャを使用して、更新ファイルをアップロード

具体例として、SharePoint 上のファイルを更新する場合の手順をご紹介します。

  1. CData SharePoint ドライバーのDownloadDocument プロシージャを使用してファイルを取得
  2. CData Access ドライバーでファイルの更新を実施
  3. SharePoint ドライバーのUploadDocument プロシージャで更新内容を反映

DataSource 接続プロパティの設定について補足いたします。接続先のクラウドストレージを識別するための一意の接頭辞を指定し、続けて目的のファイルパスまたはフォルダパスを記述します。フォルダを指定した場合は1ファイルが1テーブルとして、単一ファイルの場合は単一テーブルとして扱われます。

You can then follow the steps below to use the Data Explorer to create a FireDAC connection to Access データ.

  1. In a new VCL Forms application, expand the FireDAC node in the Data Explorer.
  2. Right-click the ODBC Data Source node in the Data Explorer.
  3. Click Add New Connection.
  4. Enter a name for the connection.
  5. In the FireDAC Connection Editor that appears, set the DataSource property to the name of the ODBC DSN for Access.

Create VCL Applications with Connectivity to Access データ

Follow the procedure below to start executing queries to Access データ from a simple VCL application that displays the results of a query in a grid.

  1. Drop a TFDConnection component onto the form and set the following properties:

    • ConnectionDefName: Select the FireDAC connection to Access データ.
    • Connected: Select True from the menu and, in the dialog that appears, enter your credentials.
  2. Drop a TFDQuery component onto the form and set the properties below:

    • Connection: Set this property to the TFDConnection component, if this component is not already specified.
    • SQL: Click the button in the SQL property and enter a query. For example:

      SELECT Orders.Freight, Customers.ContactName FROM Customers INNER JOIN Orders ON Customers.CustomerId=Orders.CustomerId
    • Active: Set this property to true.
  3. Drop a TDataSource component onto the form and set the following property:

    • DataSet: In the menu for this property, select the name of the TFDQuery component.
  4. Drop a TDBGrid control onto the form and set the following property:

    • DataSource: Select the name of the TDataSource.
  5. Drop a TFDGUIxWaitCursor onto the form — this is required to avoid a run-time error.

You now have an executable application that displays the results of the SQL Query set in the TFDQuery object.

Related Articles

Below you can find other articles for using the CData ODBC Driver with RAD Studio, Delphi, and C++ Builder.

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。