ADO.NET Provider for Microsoft SharePoint

Build 23.0.8839

Querying with the DataAdapter

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

Using the SharePointDataAdapter

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 SharePointDataAdapter is slower than the SharePointDataReader because the Fill method needs to retrieve all data from the data source before returning.

The following example selects the Id and Location columns of the Calendar table:

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