ADO.NET Provider for Gmail

Build 23.0.8839

DataAdapter を使用したクエリ

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

GmailDataAdapter の使用

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

次の例は、Inbox テーブルのId カラムとMessageBody カラムを選択します。

C#

string connectionString = "user=myuseraccount;password=mypassword;";

using (GmailConnection connection = new GmailConnection(connectionString)) {
  GmailDataAdapter dataAdapter = new GmailDataAdapter(
  "SELECT Id, MessageBody FROM Inbox", connection);

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

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

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

VB.NET

Dim connectionString As String = "user=myuseraccount;password=mypassword;"

Using connection As New GmailConnection(connectionString)
  Dim dataAdapter As New GmailDataAdapter("SELECT Id, MessageBody FROM Inbox", connection)

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

  Console.WriteLine("Contents of Inbox.")

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

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