Aracılığıyla paylaş


SqlCeDataReader Class

Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.

Inheritance Hierarchy

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

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

Syntax

'Declaration
Public Class SqlCeDataReader _
    Inherits DbDataReader
'Usage
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

The SqlCeDataReader type exposes the following members.

Properties

  Name Description
Public property Depth Gets a value indicating the depth of nesting for the current row. (Overrides DbDataReader.Depth.)
Public property FieldCount Gets the number of columns in the query's SELECT clause. (Overrides DbDataReader.FieldCount.)
Public property HasRows Gets a value that indicates whether the SqlCeDataReader contains one or more rows (Overrides DbDataReader.HasRows.)
Public property HiddenFieldCount Infrastructure.
Public property IsClosed Indicates whether the data reader is closed. (Overrides DbDataReader.IsClosed.)
Public property Item[Int32] Gets the value of the specified column in its native format given the column ordinal. (Overrides DbDataReader.Item[Int32].)
Public property Item[String] Gets the value of the specified column in its native format given the column name. (Overrides DbDataReader.Item[String].)
Public property RecordsAffected Gets the number of rows changed, inserted, or deleted by execution of the SQL statement. (Overrides DbDataReader.RecordsAffected.)
Public property VisibleFieldCount (inherited from DbDataReader)

Top

Methods

  Name Description
Public method Close Closes the SqlCeDataReader object. (Overrides DbDataReader.Close().)
Public method CreateObjRef (inherited from MarshalByRefObject)
Public method Dispose() Infrastructure. Releases the resources consumed by this SqlCeDataReader.
Protected method Dispose(Boolean) Releases the unmanaged resources used by this SqlCeDataReader, and optionally releases the managed resources as well. (Overrides DbDataReader.Dispose(Boolean).)
Public method Equals (inherited from Object)
Protected method Finalize Releases unmanaged resources and performs other cleanup operations before the SqlCeDataReader is reclaimed by garbage collection. (Overrides Object.Finalize().)
Public method GetBoolean Gets the value of the specified column as a Boolean. (Overrides DbDataReader.GetBoolean(Int32).)
Public method GetByte Gets the value of the specified column as a byte. (Overrides DbDataReader.GetByte(Int32).)
Public method GetBytes Reads a stream of bytes from the specified column offset into the buffer as an array starting at the given buffer offset. (Overrides DbDataReader.GetBytes(Int32, Int64, array<Byte[], Int32, Int32).)
Public method GetChar Not supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.GetChar(Int32).)
Public method GetChars Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset. (Overrides DbDataReader.GetChars(Int32, Int64, array<Char[], Int32, Int32).)
Public method GetData (inherited from DbDataReader)
Public method GetDataTypeName Gets the name of the source data type. (Overrides DbDataReader.GetDataTypeName(Int32).)
Public method GetDateTime Gets the value of the specified column as a DateTime object. (Overrides DbDataReader.GetDateTime(Int32).)
Protected method GetDbDataReader (inherited from DbDataReader)
Public method GetDecimal Gets the value of the specified column as a Decimal object. (Overrides DbDataReader.GetDecimal(Int32).)
Public method GetDouble Gets the value of the specified column as a double-precision floating point number. (Overrides DbDataReader.GetDouble(Int32).)
Public method GetEnumerator Infrastructure. (Overrides DbDataReader.GetEnumerator().)
Public method GetFieldType Gets the Type that is the data type of the object. (Overrides DbDataReader.GetFieldType(Int32).)
Public method GetFloat Gets the value of the specified column as a single-precision floating point number. (Overrides DbDataReader.GetFloat(Int32).)
Public method GetGuid Gets the value of the specified column as a globally unique identifier (GUID). (Overrides DbDataReader.GetGuid(Int32).)
Public method GetHashCode (inherited from Object)
Public method GetInt16 Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReader.GetInt16(Int32).)
Public method GetInt32 Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReader.GetInt32(Int32).)
Public method GetInt64 Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReader.GetInt64(Int32).)
Public method GetLifetimeService (inherited from MarshalByRefObject)
Public method GetName Gets the name of the specified column. (Overrides DbDataReader.GetName(Int32).)
Public method GetOrdinal Gets the column ordinal, given the name of the column. (Overrides DbDataReader.GetOrdinal(String).)
Public method GetProviderSpecificFieldType Gets a Object that is a representation of the underlying provider-specific field type. (Overrides DbDataReader.GetProviderSpecificFieldType(Int32).)
Public method GetProviderSpecificValue (inherited from DbDataReader)
Public method GetProviderSpecificValues (inherited from DbDataReader)
Public method GetSchemaTable Returns a DataTable that describes the column metadata of the SqlCeDataReader. (Overrides DbDataReader.GetSchemaTable().)
Public method GetSqlBinary Gets the value of the specified column as a SqlBinary.
Public method GetSqlBoolean Gets the value of the specified column as a SqlBoolean.
Public method GetSqlByte Gets the value of the specified column as a SqlByte.
Public method GetSqlDateTime Gets the value of the specified column as a SqlDateTime.
Public method GetSqlDecimal Gets the value of the specified column as a SqlDecimal.
Public method GetSqlDouble Gets the value of the specified column as a SqlDouble.
Public method GetSqlGuid Gets the value of the specified column as a SqlGuid.
Public method GetSqlInt16 Gets the value of the specified column as a SqlInt16.
Public method GetSqlInt32 Gets the value of the specified column as a SqlInt32.
Public method GetSqlInt64 Gets the value of the specified column as a SqlInt64.
Public method GetSqlMoney Gets the value of the specified column as a SqlMoney.
Public method GetSqlSingle Gets the value of the specified column as a SqlSingle.
Public method GetSqlString Gets the value of the specified column as a SqlString.
Public method GetString Gets the value of the specified column as a string. (Overrides DbDataReader.GetString(Int32).)
Public method GetType (inherited from Object)
Public method GetValue Gets the value of the column at the specified ordinal in its native format. (Overrides DbDataReader.GetValue(Int32).)
Public method GetValues Gets all the attribute columns in the current row. (Overrides DbDataReader.GetValues(array<Object[]).)
Public method InitializeLifetimeService (inherited from MarshalByRefObject)
Protected method IsCommandBehavior Determines whether the specified CommandBehavior matches that of this SqlCeDataReader.
Public method IsDBNull Gets a value indicating whether the column contains nonexistent or missing values. (Overrides DbDataReader.IsDBNull(Int32).)
Protected method MemberwiseClone() (inherited from Object)
Protected method MemberwiseClone(Boolean) (inherited from MarshalByRefObject)
Public method NextResult Not supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.NextResult().)
Protected method OnMove Infrastructure.
Public method Read Advances SqlCeDataReader to the next record. (Overrides DbDataReader.Read().)
Public method Seek Places the SqlCeDataReader on the record with indexed values that match the specified parameters.
Public method ToString (inherited from Object)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IDataRecord.GetData (inherited from DbDataReader)

Top

Remarks

To create a SqlCeDataReader, you must call the ExecuteReader method of the SqlCeCommand object, rather than directly using a constructor.

While the SqlCeDataReader is in use, the associated SqlCeConnection is busy serving the SqlCeDataReader. In this state, you can create multiple readers in the same connection.

Changes made to a result set by another process or thread while the data is being read may be visible to the user of the SqlCeDataReader; however, the precise behavior is dependent on when these occur.

IsClosed and RecordsAffected are the only properties you can call after the SqlCeDataReader is closed. Although the RecordsAffected property can be accessed at any time while the SqlCeDataReader exists, always call Close before returning the value of RecordsAffected to ensure an accurate return value.

Examples

The following example creates a SqlCeConnection, a SqlCeCommand, and a SqlCeDataReader. The example reads through the data and writes it out to the console, and then closes the SqlCeDataReader and the 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();
}

Thread Safety

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.

See Also

Reference

System.Data.SqlServerCe Namespace