ADO.NET Provider for Microsoft SharePoint Excel

Build 23.0.8839

DataAdapter を使用したクエリ

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

Microsoft SharePoint ExcelDataAdapter の使用

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

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

C#

string connectionString = "Url=https://myorg.sharepoint.com;User=admin@myorg.onmicrosoft.com;Password=password;File=Book1.xlsx;";

using (Microsoft SharePoint ExcelConnection connection = new Microsoft SharePoint ExcelConnection(connectionString)) {
  Microsoft SharePoint ExcelDataAdapter dataAdapter = new Microsoft SharePoint ExcelDataAdapter(
  "SELECT Id, Name FROM Account", connection);

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

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

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

VB.NET

Dim connectionString As String = "Url=https://myorg.sharepoint.com;User=admin@myorg.onmicrosoft.com;Password=password;File=Book1.xlsx;"

Using connection As New Microsoft SharePoint ExcelConnection(connectionString)
  Dim dataAdapter As New Microsoft SharePoint ExcelDataAdapter("SELECT Id, Name FROM Account", connection)

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

  Console.WriteLine("Contents of Account.")

  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