Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

SqlCeDataReader Class

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

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
public class SqlCeDataReader : DbDataReader

The SqlCeDataReader type exposes the following members.

  NameDescription
Public propertyDepthGets a value indicating the depth of nesting for the current row. (Overrides DbDataReader.Depth.)
Public propertyFieldCountGets the number of columns in the query's SELECT clause. (Overrides DbDataReader.FieldCount.)
Public propertyHasRowsGets a value that indicates whether the SqlCeDataReader contains one or more rows (Overrides DbDataReader.HasRows.)
Public propertyHiddenFieldCountInfrastructure.
Public propertyIsClosedIndicates whether the data reader is closed. (Overrides DbDataReader.IsClosed.)
Public propertyItem[Int32]Gets the value of the specified column in its native format given the column ordinal. (Overrides DbDataReader.Item[Int32].)
Public propertyItem[String]Gets the value of the specified column in its native format given the column name. (Overrides DbDataReader.Item[String].)
Public propertyRecordsAffectedGets the number of rows changed, inserted, or deleted by execution of the SQL statement. (Overrides DbDataReader.RecordsAffected.)
Public propertyVisibleFieldCount (inherited from DbDataReader)
Top
  NameDescription
Public methodCloseCloses the SqlCeDataReader object. (Overrides DbDataReader.Close().)
Public methodCreateObjRef (inherited from MarshalByRefObject)
Public methodDispose()Infrastructure. Releases the resources consumed by this SqlCeDataReader.
Protected methodDispose(Boolean)Releases the unmanaged resources used by this SqlCeDataReader, and optionally releases the managed resources as well. (Overrides DbDataReader.Dispose(Boolean).)
Public methodEquals (inherited from Object)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the SqlCeDataReader is reclaimed by garbage collection. (Overrides Object.Finalize().)
Public methodGetBooleanGets the value of the specified column as a Boolean. (Overrides DbDataReader.GetBoolean(Int32).)
Public methodGetByteGets the value of the specified column as a byte. (Overrides DbDataReader.GetByte(Int32).)
Public methodGetBytesReads 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, Byte[], Int32, Int32).)
Public methodGetCharNot supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.GetChar(Int32).)
Public methodGetCharsReads 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, Char[], Int32, Int32).)
Public methodGetData (inherited from DbDataReader)
Public methodGetDataTypeNameGets the name of the source data type. (Overrides DbDataReader.GetDataTypeName(Int32).)
Public methodGetDateTimeGets the value of the specified column as a DateTime object. (Overrides DbDataReader.GetDateTime(Int32).)
Protected methodGetDbDataReader (inherited from DbDataReader)
Public methodGetDecimalGets the value of the specified column as a Decimal object. (Overrides DbDataReader.GetDecimal(Int32).)
Public methodGetDoubleGets the value of the specified column as a double-precision floating point number. (Overrides DbDataReader.GetDouble(Int32).)
Public methodGetEnumeratorInfrastructure. (Overrides DbDataReader.GetEnumerator().)
Public methodGetFieldTypeGets the Type that is the data type of the object. (Overrides DbDataReader.GetFieldType(Int32).)
Public methodGetFloatGets the value of the specified column as a single-precision floating point number. (Overrides DbDataReader.GetFloat(Int32).)
Public methodGetGuidGets the value of the specified column as a globally unique identifier (GUID). (Overrides DbDataReader.GetGuid(Int32).)
Public methodGetHashCode (inherited from Object)
Public methodGetInt16Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReader.GetInt16(Int32).)
Public methodGetInt32Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReader.GetInt32(Int32).)
Public methodGetInt64Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReader.GetInt64(Int32).)
Public methodGetLifetimeService (inherited from MarshalByRefObject)
Public methodGetNameGets the name of the specified column. (Overrides DbDataReader.GetName(Int32).)
Public methodGetOrdinalGets the column ordinal, given the name of the column. (Overrides DbDataReader.GetOrdinal(String).)
Public methodGetProviderSpecificFieldTypeGets a Object that is a representation of the underlying provider-specific field type. (Overrides DbDataReader.GetProviderSpecificFieldType(Int32).)
Public methodGetProviderSpecificValue (inherited from DbDataReader)
Public methodGetProviderSpecificValues (inherited from DbDataReader)
Public methodGetSchemaTableReturns a DataTable that describes the column metadata of the SqlCeDataReader. (Overrides DbDataReader.GetSchemaTable().)
Public methodGetSqlBinaryGets the value of the specified column as a SqlBinary.
Public methodGetSqlBooleanGets the value of the specified column as a SqlBoolean.
Public methodGetSqlByteGets the value of the specified column as a SqlByte.
Public methodGetSqlDateTimeGets the value of the specified column as a SqlDateTime.
Public methodGetSqlDecimalGets the value of the specified column as a SqlDecimal.
Public methodGetSqlDoubleGets the value of the specified column as a SqlDouble.
Public methodGetSqlGuidGets the value of the specified column as a SqlGuid.
Public methodGetSqlInt16Gets the value of the specified column as a SqlInt16.
Public methodGetSqlInt32Gets the value of the specified column as a SqlInt32.
Public methodGetSqlInt64Gets the value of the specified column as a SqlInt64.
Public methodGetSqlMoneyGets the value of the specified column as a SqlMoney.
Public methodGetSqlSingleGets the value of the specified column as a SqlSingle.
Public methodGetSqlStringGets the value of the specified column as a SqlString.
Public methodGetStringGets the value of the specified column as a string. (Overrides DbDataReader.GetString(Int32).)
Public methodGetType (inherited from Object)
Public methodGetValueGets the value of the column at the specified ordinal in its native format. (Overrides DbDataReader.GetValue(Int32).)
Public methodGetValuesGets all the attribute columns in the current row. (Overrides DbDataReader.GetValues(Object[]).)
Public methodInitializeLifetimeService (inherited from MarshalByRefObject)
Protected methodIsCommandBehaviorDetermines whether the specified CommandBehavior matches that of this SqlCeDataReader.
Public methodIsDBNullGets a value indicating whether the column contains nonexistent or missing values. (Overrides DbDataReader.IsDBNull(Int32).)
Protected methodMemberwiseClone() (inherited from Object)
Protected methodMemberwiseClone(Boolean) (inherited from MarshalByRefObject)
Public methodNextResultNot supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.NextResult().)
Protected methodOnMoveInfrastructure.
Public methodReadAdvances SqlCeDataReader to the next record. (Overrides DbDataReader.Read().)
Public methodSeekPlaces the SqlCeDataReader on the record with indexed values that match the specified parameters.
Public methodToString (inherited from Object)
Top
  NameDescription
Explicit interface implemetationPrivate methodIDataRecord.GetData (inherited from DbDataReader)
Top

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.

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.

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();
}



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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.