ADO.NET Provider for Bing Ads

Build 23.0.8839

DataAdapter を使用したクエリ

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

BingAdsDataAdapter の使用

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

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

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;AccountId=442311;CustomerId=5521444;DeveloperToken=11112332233;";

using (BingAdsConnection connection = new BingAdsConnection(connectionString)) {
  BingAdsDataAdapter dataAdapter = new BingAdsDataAdapter(
  "SELECT Id, Name FROM AdGroups", connection);

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

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

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

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;AccountId=442311;CustomerId=5521444;DeveloperToken=11112332233;"

Using connection As New BingAdsConnection(connectionString)
  Dim dataAdapter As New BingAdsDataAdapter("SELECT Id, Name FROM AdGroups", connection)

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

  Console.WriteLine("Contents of AdGroups.")

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

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