ADO.NET Provider for Couchbase

Build 25.0.9434

Querying with the DataAdapter

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

Using the CouchbaseDataAdapter

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

The following example selects the Name and TotalDue columns of the [MyBucket].[MyScope].[Customer] table:

C#

string connectionString = "User='myusername';Password='mypassword';Server='http://couchbase40'";

using (CouchbaseConnection connection = new CouchbaseConnection(connectionString)) {
  CouchbaseDataAdapter dataAdapter = new CouchbaseDataAdapter(
  "SELECT Name, TotalDue FROM [MyBucket].[MyScope].[Customer]", connection);

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

  Console.WriteLine("Contents of [MyBucket].[MyScope].[Customer].");

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

VB.NET

Dim connectionString As String = "User='myusername';Password='mypassword';Server='http://couchbase40'"

Using connection As New CouchbaseConnection(connectionString)
  Dim dataAdapter As New CouchbaseDataAdapter("SELECT Name, TotalDue FROM [MyBucket].[MyScope].[Customer]", connection)

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

  Console.WriteLine("Contents of [MyBucket].[MyScope].[Customer].")

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

Copyright (c) 2025 CData Software, Inc. - All rights reserved.
Build 25.0.9434