ADO.NET Provider for Google Ads

Build 23.0.8839

DataAdapter を使用したクエリ

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

GoogleAdsDataAdapter の使用

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

次の例は、CampaignPerformance テーブルのClicks カラムとDevice カラムを選択します。

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;DeveloperToken=myDeveloperToken;ClientCustomerId=myClientCustomerId;";

using (GoogleAdsConnection connection = new GoogleAdsConnection(connectionString)) {
  GoogleAdsDataAdapter dataAdapter = new GoogleAdsDataAdapter(
  "SELECT Clicks, Device FROM CampaignPerformance", connection);

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

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

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

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;DeveloperToken=myDeveloperToken;ClientCustomerId=myClientCustomerId;"

Using connection As New GoogleAdsConnection(connectionString)
  Dim dataAdapter As New GoogleAdsDataAdapter("SELECT Clicks, Device FROM CampaignPerformance", connection)

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

  Console.WriteLine("Contents of CampaignPerformance.")

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

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