ADO.NET Provider for YouTube Analytics

Build 22.0.8479

データの変更

アダプターのUpdate メソッドを使用して、データを更新します。このオーバーロードされたメソッドは、パラメータとしてDataTable を受け取ることができ、データソースに対して行われたすべての変更をコミットします。 データテーブルの名前は、引数として渡すことができ、従来の方法でデータセット全体を更新するためにも使用されます。 データテーブルをUpdate メソッドへの引数として使用する場合、アダプターは、データテーブルに対して行われた変更を評価し、行ごとに適切なコマンド(INSERT、UPDATE、またはDELETE)を実行します。

次の例は、Groups エントリの1つであるContentDetails_ItemType を更新します。

C#

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

  dataAdapter.UpdateCommand = new YouTubeAnalyticsCommand(
    "UPDATE Groups SET ContentDetails_ItemType = @ContentDetails_ItemType " +
    "WHERE Id = @Id", connection);
 
  dataAdapter.UpdateCommand.Parameters.Add(new YouTubeAnalyticsParameter("@ContentDetails_ItemType", DbType.String, "ContentDetails_ItemType"));
  dataAdapter.UpdateCommand.Parameters.Add(new YouTubeAnalyticsParameter("@Id", DbType.String, "Id"));
  dataAdapter.UpdateCommand.Parameters[1].SourceVersion = DataRowVersion.Original;

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

  DataRow firstrow = table.Rows[0];
  firstrow["ContentDetails_ItemType"] = "youtube#channel";

  dataAdapter.Update(table);

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

VB.NET

Using connection As New YouTubeAnalyticsConnection(connectionString)
  Dim dataAdapter As New YouTubeAnalyticsDataAdapter(
    "SELECT Snippet_Title, ContentDetails_ItemType FROM Groups", connection)
  
  dataAdapter.UpdateCommand = New YouTubeAnalyticsCommand(
    "UPDATE Groups SET ContentDetails_ItemType = @ContentDetails_ItemType " +
    "WHERE Id = @Id", connection)
  
  dataAdapter.UpdateCommand.Parameters.Add(new YouTubeAnalyticsParameter("@ContentDetails_ItemType", DbType.String, "ContentDetails_ItemType"))
  dataAdapter.UpdateCommand.Parameters.Add(new YouTubeAnalyticsParameter("@Id", DbType.String, "Id"))
  dataAdapter.UpdateCommand.Parameters(1).SourceVersion = DataRowVersion.Original
  
  Dim table As New DataTable()
  dataAdapter.Fill(table)
  
  Dim firstrow As DataRow = table.Rows(0)
  firstrow("ContentDetails_ItemType") = "youtube#channel"
  
  dataAdapter.Update(table)
  
  Console.WriteLine("Rows after update.")
  
  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("Snippet_Title"), row("ContentDetails_ItemType"))
  Next
End Using

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479