ADO.NET Provider for Microsoft SharePoint

Build 23.0.8839

DataAdapter を使用したクエリ

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

SharePointDataAdapter の使用

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

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

C#

string connectionString = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;";

using (SharePointConnection connection = new SharePointConnection(connectionString)) {
  SharePointDataAdapter dataAdapter = new SharePointDataAdapter(
  "SELECT Id, Location FROM Calendar", connection);

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

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

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

VB.NET

Dim connectionString As String = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;"

Using connection As New SharePointConnection(connectionString)
  Dim dataAdapter As New SharePointDataAdapter("SELECT Id, Location FROM Calendar", connection)

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

  Console.WriteLine("Contents of Calendar.")

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

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