DB2DataReader クラス

順方向のみのデータ行のストリームをデータベースから読み取る手段を提供します。

ネーム・スペース:
IBM.Data.DB2
アセンブリー:
IBM.Data.DB2 ( IBM.Data.DB2.dll内)

.NET Framework 2.0、3.0、3.5 および 4.0 の継承階層


System.Object
   System.MarshalByRefObject
      System.Data.Common.DbDataReader
         IBM.Data.DB2.DB2DataReader

.NET Framework 2.0、3.0、3.5 および 4.0 の構文


[Visual Basic]
NotInheritable Public Class DB2DataReader
   Inherits MarshalByRefObject
   Implements IDataReader, IDisposable, IDataRecord, IEnumerable
[C#]
public sealed class DB2DataReader : MarshalByRefObject,
   IDataReader, IDisposable, IDataRecord, IEnumerable
[C++]
public __gc __sealed class DB2DataReader : public
   MarshalByRefObject, IDataReader, IDisposable, IDataRecord,
   IEnumerable
[JScript]
public class DB2DataReader extends MarshalByRefObject implements
   IDataReader, IDisposable, IDataRecord, IEnumerable

注釈

DB2DataReaderを作成するには、コンストラクターを直接使用するのではなく、 DB2Command オブジェクトの DB2®Command.ExecuteReader メソッドを呼び出す必要があります。

同じ DB2Connection インスタンスを使用する複数の DB2DataReader インスタンスからデータに並行してアクセスできます。 各 DB2DataReader インスタンスは、それ自体の DB2Command インスタンスと関連付ける必要があります。

データの読み取り中に別のプロセスまたはスレッドによって結果セットに加えられた変更は、 DB2DataReaderのユーザーに表示される可能性があります。 ただし、厳密な動作はタイミングに応じて異なります。

アプリケーションで結果セットを複数方向にスクロールする必要がある場合、または行を挿入、更新、および削除する必要がある場合は、 DB2ResultSet インスタンスを使用できます。

DB2DataReader を閉じた後に呼び出すことができるプロパティーは、 IsClosedRecordsAffected のみです。 場合によっては、RecordsAffected を呼び出す前に Close を呼び出す必要があるかもしれません。

[Visual Basic、C#] 以下の例では、 DB2接続DB2コマンド 、および DB2DataReaderを作成します。 この例はデータを読み通して、それをコンソールに書き出します。 最後に、この例では DB2DataReaderを閉じてから、 DB2Connectionを閉じます。

[Visual Basic]
Public Sub ReadMyData(myConnString As String)
    Dim mySelectQuery As String = "SELECT SALES, SALES_PERSON FROM SALES"
    Dim myConnection As New DB2Connection(myConnString)
    Dim myCommand As New DB2Command(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As DB2DataReader
    myReader = myCommand.ExecuteReader()
    ' Always call Read before accessing data.
    While myReader.Read()
        Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
           + myReader.GetString(1))
    End While
    ' always call Close when done reading.
    myReader.Close()
    ' Close the connection when done with it.
    myConnection.Close()
End Sub

[C#]
public void ReadMyData(string myConnString) {
   string mySelectQuery = "SELECT SALES, SALES_PERSON FROM SALES";
   DB2Connection myConnection = new DB2Connection(myConnString);
   DB2Command myCommand = new DB2Command(mySelectQuery,myConnection);
   myConnection.Open();
   DB2DataReader myReader;
   myReader = myCommand.ExecuteReader();
   // Always call Read before accessing data.
   while (myReader.Read()) {
      Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
   }
   // always call Close when done reading.
   myReader.Close();
   // Close the connection when done with it.
   myConnection.Close();
}

スレッドの安全性

このタイプの public static (Visual Basic での Shared) メンバーはすべて、 マルチスレッド操作に関して安全です。 どのインスタンス・メンバーも、スレッド・セーフであるとはかぎりません。