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 | |
---|---|---|
Depth | Gets a value indicating the depth of nesting for the current row. (Overrides DbDataReader.Depth.) | |
FieldCount | Gets the number of columns in the query's SELECT clause. (Overrides DbDataReader.FieldCount.) | |
HasRows | Gets a value that indicates whether the SqlCeDataReader contains one or more rows (Overrides DbDataReader.HasRows.) | |
HiddenFieldCount | Infrastructure. | |
IsClosed | Indicates whether the data reader is closed. (Overrides DbDataReader.IsClosed.) | |
Item[Int32] | Gets the value of the specified column in its native format given the column ordinal. (Overrides DbDataReader.Item[Int32].) | |
Item[String] | Gets the value of the specified column in its native format given the column name. (Overrides DbDataReader.Item[String].) | |
RecordsAffected | Gets the number of rows changed, inserted, or deleted by execution of the SQL statement. (Overrides DbDataReader.RecordsAffected.) | |
VisibleFieldCount | (inherited from DbDataReader) |
Top
Methods
Name | Description | |
---|---|---|
Close | Closes the SqlCeDataReader object. (Overrides DbDataReader.Close().) | |
CreateObjRef | (inherited from MarshalByRefObject) | |
Dispose() | Infrastructure. Releases the resources consumed by this SqlCeDataReader. | |
Dispose(Boolean) | Releases the unmanaged resources used by this SqlCeDataReader, and optionally releases the managed resources as well. (Overrides DbDataReader.Dispose(Boolean).) | |
Equals | (inherited from Object) | |
Finalize | Releases unmanaged resources and performs other cleanup operations before the SqlCeDataReader is reclaimed by garbage collection. (Overrides Object.Finalize().) | |
GetBoolean | Gets the value of the specified column as a Boolean. (Overrides DbDataReader.GetBoolean(Int32).) | |
GetByte | Gets the value of the specified column as a byte. (Overrides DbDataReader.GetByte(Int32).) | |
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).) | |
GetChar | Not supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.GetChar(Int32).) | |
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).) | |
GetData | (inherited from DbDataReader) | |
GetDataTypeName | Gets the name of the source data type. (Overrides DbDataReader.GetDataTypeName(Int32).) | |
GetDateTime | Gets the value of the specified column as a DateTime object. (Overrides DbDataReader.GetDateTime(Int32).) | |
GetDbDataReader | (inherited from DbDataReader) | |
GetDecimal | Gets the value of the specified column as a Decimal object. (Overrides DbDataReader.GetDecimal(Int32).) | |
GetDouble | Gets the value of the specified column as a double-precision floating point number. (Overrides DbDataReader.GetDouble(Int32).) | |
GetEnumerator | Infrastructure. (Overrides DbDataReader.GetEnumerator().) | |
GetFieldType | Gets the Type that is the data type of the object. (Overrides DbDataReader.GetFieldType(Int32).) | |
GetFloat | Gets the value of the specified column as a single-precision floating point number. (Overrides DbDataReader.GetFloat(Int32).) | |
GetGuid | Gets the value of the specified column as a globally unique identifier (GUID). (Overrides DbDataReader.GetGuid(Int32).) | |
GetHashCode | (inherited from Object) | |
GetInt16 | Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReader.GetInt16(Int32).) | |
GetInt32 | Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReader.GetInt32(Int32).) | |
GetInt64 | Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReader.GetInt64(Int32).) | |
GetLifetimeService | (inherited from MarshalByRefObject) | |
GetName | Gets the name of the specified column. (Overrides DbDataReader.GetName(Int32).) | |
GetOrdinal | Gets the column ordinal, given the name of the column. (Overrides DbDataReader.GetOrdinal(String).) | |
GetProviderSpecificFieldType | Gets a Object that is a representation of the underlying provider-specific field type. (Overrides DbDataReader.GetProviderSpecificFieldType(Int32).) | |
GetProviderSpecificValue | (inherited from DbDataReader) | |
GetProviderSpecificValues | (inherited from DbDataReader) | |
GetSchemaTable | Returns a DataTable that describes the column metadata of the SqlCeDataReader. (Overrides DbDataReader.GetSchemaTable().) | |
GetSqlBinary | Gets the value of the specified column as a SqlBinary. | |
GetSqlBoolean | Gets the value of the specified column as a SqlBoolean. | |
GetSqlByte | Gets the value of the specified column as a SqlByte. | |
GetSqlDateTime | Gets the value of the specified column as a SqlDateTime. | |
GetSqlDecimal | Gets the value of the specified column as a SqlDecimal. | |
GetSqlDouble | Gets the value of the specified column as a SqlDouble. | |
GetSqlGuid | Gets the value of the specified column as a SqlGuid. | |
GetSqlInt16 | Gets the value of the specified column as a SqlInt16. | |
GetSqlInt32 | Gets the value of the specified column as a SqlInt32. | |
GetSqlInt64 | Gets the value of the specified column as a SqlInt64. | |
GetSqlMoney | Gets the value of the specified column as a SqlMoney. | |
GetSqlSingle | Gets the value of the specified column as a SqlSingle. | |
GetSqlString | Gets the value of the specified column as a SqlString. | |
GetString | Gets the value of the specified column as a string. (Overrides DbDataReader.GetString(Int32).) | |
GetType | (inherited from Object) | |
GetValue | Gets the value of the column at the specified ordinal in its native format. (Overrides DbDataReader.GetValue(Int32).) | |
GetValues | Gets all the attribute columns in the current row. (Overrides DbDataReader.GetValues(array<Object[]).) | |
InitializeLifetimeService | (inherited from MarshalByRefObject) | |
IsCommandBehavior | Determines whether the specified CommandBehavior matches that of this SqlCeDataReader. | |
IsDBNull | Gets a value indicating whether the column contains nonexistent or missing values. (Overrides DbDataReader.IsDBNull(Int32).) | |
MemberwiseClone() | (inherited from Object) | |
MemberwiseClone(Boolean) | (inherited from MarshalByRefObject) | |
NextResult | Not supported in the .NET Compact Framework Data Provider for SQL Server Compact. (Overrides DbDataReader.NextResult().) | |
OnMove | Infrastructure. | |
Read | Advances SqlCeDataReader to the next record. (Overrides DbDataReader.Read().) | |
Seek | Places the SqlCeDataReader on the record with indexed values that match the specified parameters. | |
ToString | (inherited from Object) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
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.