ADO.NET Provider for SendGrid

Build 23.0.8839

Querying with the DataAdapter

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

Using the SendGridDataAdapter

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

The following example selects the Title and Subject columns of the MarketingCampaigns table:

C#

string connectionString = "APIKey=abc123;";

using (SendGridConnection connection = new SendGridConnection(connectionString)) {
  SendGridDataAdapter dataAdapter = new SendGridDataAdapter(
  "SELECT Title, Subject FROM MarketingCampaigns", connection);

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

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

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

VB.NET

Dim connectionString As String = "APIKey=abc123;"

Using connection As New SendGridConnection(connectionString)
  Dim dataAdapter As New SendGridDataAdapter("SELECT Title, Subject FROM MarketingCampaigns", connection)

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

  Console.WriteLine("Contents of MarketingCampaigns.")

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

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