ADO.NET Provider for YouTube Analytics

Build 23.0.8839

Querying with the DataAdapter

The CData ADO.NET Provider for YouTube Analytics implements two ADO.NET interfaces you can use to retrieve data from YouTube Analytics: YouTubeAnalyticsDataAdapter and YouTubeAnalyticsDataReader objects. Whereas YouTubeAnalyticsDataAdapter objects retrieve a single result set of all the data that matches a query, YouTubeAnalyticsDataReader objects fetch data in subset increments as needed.

Using the YouTubeAnalyticsDataAdapter

Use the adapter's Fill method to retrieve data from the data source. An empty DataTable instance is passed as an argument to the Fill method. When the method returns, the DataTable instance is populated with the queried data. Note that the YouTubeAnalyticsDataAdapter is slower than the YouTubeAnalyticsDataReader because the Fill method needs to retrieve all data from the data source before returning.

The following example selects the Snippet_Title and ContentDetails_ItemType columns of the Groups table:

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;ContentOwnerId=MyContentOwnerId;ChannelId=ChannelId;";

using (YouTubeAnalyticsConnection connection = new YouTubeAnalyticsConnection(connectionString)) {
  YouTubeAnalyticsDataAdapter dataAdapter = new YouTubeAnalyticsDataAdapter(
  "SELECT Snippet_Title, ContentDetails_ItemType FROM Groups", connection);

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

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

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

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;ContentOwnerId=MyContentOwnerId;ChannelId=ChannelId;"

Using connection As New YouTubeAnalyticsConnection(connectionString)
  Dim dataAdapter As New YouTubeAnalyticsDataAdapter("SELECT Snippet_Title, ContentDetails_ItemType FROM Groups", connection)

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

  Console.WriteLine("Contents of Groups.")

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

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