ADO.NET Provider for Smaregi

Build 23.0.8839

DataAdapter を使用したクエリ

CData ADO.NET Provider for Smaregi では、次の2つのネイティブ.NET インターフェースを使用して、Smaregi からデータを取得できます。SmaregiDataAdapter オブジェクトおよびSmaregiDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。SmaregiDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、SmaregiDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。

SmaregiDataAdapter の使用

アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、SmaregiDataAdapter はSmaregiDataReader よりも時間がかかります。

次の例は、Products テーブルのProductName カラムとDescription カラムを選択します。

C#

string connectionString = "ContractId=mycontractid;AccessToken=myaccesstoken;";

using (SmaregiConnection connection = new SmaregiConnection(connectionString)) {
  SmaregiDataAdapter dataAdapter = new SmaregiDataAdapter(
  "SELECT ProductName, Description FROM Products", connection);

  DataTable table = new DataTable();
  dataAdapter.Fill(table);

  Console.WriteLine("Contents of Products.");

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["ProductName"], row["Description"]);
  }
}

VB.NET

Dim connectionString As String = "ContractId=mycontractid;AccessToken=myaccesstoken;"

Using connection As New SmaregiConnection(connectionString)
  Dim dataAdapter As New SmaregiDataAdapter("SELECT ProductName, Description FROM Products", connection)

  Dim table As New DataTable()
  dataAdapter.Fill(table)

  Console.WriteLine("Contents of Products.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("ProductName"), row("Description"))
  Next
End Using

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839