ADO.NET Provider for IBM Cloud Data Engine

Build 23.0.8839

DataReader を使用したクエリ

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

IBMCloudSQLQueryDataReader の使用

IBMCloudSQLQueryDataReader はページ単位でデータを取得できるため、IBMCloudSQLQueryDataAdapter よりもデータの取得が高速です。IBMCloudSQLQueryDataReader からデータを読み取っていくと、必要に応じて一定の間隔で、データソースからの結果の次のページが要求されます。このため、結果が高速に返されます。 次の例は、[CloudObjectStorage_1].[SampleBucket_1].Jobs テーブルからすべてのカラムを選択します。

C#

string connectionString = "Api Key=MyAPIKey;";

using (IBMCloudSQLQueryConnection connection = new IBMCloudSQLQueryConnection(connectionString)) {
  IBMCloudSQLQueryCommand cmd = new IBMCloudSQLQueryCommand("SELECT * FROM [CloudObjectStorage_1].[SampleBucket_1].Jobs", connection);
  
  IBMCloudSQLQueryDataReader rdr = cmd.ExecuteReader();

  while (rdr.Read()) {
    Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Id"], rdr["Status"]));
  }
}

VB.NET

Dim connectionString As String = "Api Key=MyAPIKey;"

Using connection As New IBMCloudSQLQueryConnection(connectionString)
  Dim cmd As New IBMCloudSQLQueryCommand("SELECT * FROM [CloudObjectStorage_1].[SampleBucket_1].Jobs", connection)

  Dim rdr As IBMCloudSQLQueryDataReader = cmd.ExecuteReader()

  While rdr.Read()
    Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("Id"), rdr("Status")))
  End While
End Using

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