Share via


SqlCeDataReader クラス

データ ソースからデータ行の前方向ストリームを読み取る方法を提供します。このクラスは継承できません。

名前空間:  System.Data.SqlServerCe
アセンブリ:  System.Data.SqlServerCe (System.Data.SqlServerCe.dll)

構文

'宣言
Public Class SqlCeDataReader _
    Inherits DbDataReader
'使用
Dim instance As SqlCeDataReader
public class SqlCeDataReader : DbDataReader
public ref class SqlCeDataReader : public DbDataReader
type SqlCeDataReader =  
    class
        inherit DbDataReader
    end
public class SqlCeDataReader extends DbDataReader

説明

SqlCeDataReader を作成するには、コンストラクタを直接使用せずに、SqlCeCommand オブジェクトの ExecuteReader メソッドを呼び出す必要があります。

SqlCeDataReader の使用中は、関連付けられた SqlCeConnection は、その SqlCeDataReader によって使用されるためビジー状態になります。この状態では、同じ接続で複数のリーダーを作成できます。

データの読み取り中に別のプロセスまたはスレッドが結果セットに加えた変更が、SqlCeDataReader のユーザーに表示されることがあります。実際の動作は、いつ変更が行われたかによって決まります。

SqlCeDataReader を閉じた後に呼び出すことができるのは、IsClosed プロパティと RecordsAffected プロパティだけです。RecordsAffected プロパティは、SqlCeDataReader が存在している間はいつでも呼び出すことができますが、正しい戻り値を得るために、RecordsAffected の値を取得する前には、必ず Close を呼び出してください。

使用例

SqlCeConnectionSqlCeCommand、および SqlCeDataReader を作成する例を次に示します。この例では、データを読み取り、コンソールに出力した後で、SqlCeDataReader と SqlCeConnection を閉じます。

Dim conn As SqlCeConnection = Nothing
Dim cmd As SqlCeCommand = Nothing
Dim rdr As SqlCeDataReader = Nothing

Try
    ' Open the connection and create a SQL command
    '
    conn = New SqlCeConnection("Data Source = AdventureWorks.sdf")
    conn.Open()

    cmd = New SqlCeCommand("SELECT * FROM DimEmployee", conn)

    rdr = cmd.ExecuteReader()

    ' Iterate through the results
    '
    While rdr.Read()
        Dim employeeID As Integer = rdr.GetInt32(0) ' or: rdr["EmployeeKey"];
        Dim lastName As String = rdr.GetString(5) ' or: rdr["FirstName"];
    End While

    ' Always dispose data readers and commands as soon as practicable
    '
    rdr.Close()
    cmd.Dispose()
Finally
    ' Close the connection when no longer needed
    '
    conn.Close()
End Try
SqlCeConnection conn = null;
SqlCeCommand cmd = null;
SqlCeDataReader rdr = null;

try
{
    // Open the connection and create a SQL command
    //
    conn = new SqlCeConnection("Data Source = AdventureWorks.sdf");
    conn.Open();

    cmd = new SqlCeCommand("SELECT * FROM DimEmployee", conn);

    rdr = cmd.ExecuteReader();

    // Iterate through the results
    //
    while (rdr.Read())
    {
        int employeeID = rdr.GetInt32(0);   // or: rdr["EmployeeKey"];
        string lastName = rdr.GetString(5); // or: rdr["FirstName"];
    }

    // Always dispose data readers and commands as soon as practicable
    //
    rdr.Close();
    cmd.Dispose();
}
finally
{
    // Close the connection when no longer needed
    //
    conn.Close();
}

継承階層

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System.Data.Common. . :: . .DbDataReader
      System.Data.SqlServerCe..::..SqlCeDataReader
        System.Data.SqlServerCe. . :: . .SqlCeResultSet

スレッド セーフ

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

関連項目

参照

SqlCeDataReader メンバー

System.Data.SqlServerCe 名前空間