ADO.NET Provider for SFTP

Build 23.0.8839

DataAdapter を使用したクエリ

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

SFTPDataAdapter の使用

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

次の例は、Notes テーブルのFilesize カラムとFilename カラムを選択します。

C#

string connectionString = "RemoteHost=MySFTPServer;";

using (SFTPConnection connection = new SFTPConnection(connectionString)) {
  SFTPDataAdapter dataAdapter = new SFTPDataAdapter(
  "SELECT Filesize, Filename FROM Notes", connection);

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

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

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

VB.NET

Dim connectionString As String = "RemoteHost=MySFTPServer;"

Using connection As New SFTPConnection(connectionString)
  Dim dataAdapter As New SFTPDataAdapter("SELECT Filesize, Filename FROM Notes", connection)

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

  Console.WriteLine("Contents of Notes.")

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

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