Share via


SqlCeDataReader 类

提供从数据源读取数据行的只进流的方法。无法继承此类。

继承层次结构

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

命名空间:  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 类型公开以下成员。

属性

  名称 说明
公共属性 Depth 获取一个值,该值指示当前行的嵌套深度。 (覆盖 DbDataReader.Depth。)
公共属性 FieldCount 获取查询表的 SELECT 子句中的列数。 (覆盖 DbDataReader.FieldCount。)
公共属性 HasRows 获取一个值,该值指示 SqlCeDataReader 是否包含一行或多行 (覆盖 DbDataReader.HasRows。)
公共属性 HiddenFieldCount 基础结构。
公共属性 IsClosed 指示是否可关闭数据读取器。 (覆盖 DbDataReader.IsClosed。)
公共属性 Item[Int32] 在给定列序号的情况下,获取指定列的以本机格式表示的值。 (覆盖 DbDataReader.Item[Int32]。)
公共属性 Item[String] 在给定列名称的情况下,获取指定列的以本机格式表示的值。 (覆盖 DbDataReader.Item[String]。)
公共属性 RecordsAffected 通过执行 SQL 语句获取更改、插入或删除的行数。 (覆盖 DbDataReader.RecordsAffected。)
公共属性 VisibleFieldCount (继承自 DbDataReader

页首

方法

  名称 说明
公共方法 Close 关闭 SqlCeDataReader 对象。 (覆盖 DbDataReader.Close()。)
公共方法 CreateObjRef (继承自 MarshalByRefObject
公共方法 Dispose() 基础结构。释放此 SqlCeDataReader 使用的资源。
受保护方法 Dispose(Boolean) 释放此 SqlCeDataReader 类使用的非托管资源,并还可以选择释放托管资源。 (覆盖 DbDataReader.Dispose(Boolean)。)
公共方法 Equals (继承自 Object
受保护方法 Finalize 在通过垃圾回收将 SqlCeDataReader 回收之前,释放非托管资源并执行其他清理操作。 (覆盖 Object.Finalize()。)
公共方法 GetBoolean 获取指定列的布尔值形式的值。 (覆盖 DbDataReader.GetBoolean(Int32)。)
公共方法 GetByte 获取指定列的字节形式的值。 (覆盖 DbDataReader.GetByte(Int32)。)
公共方法 GetBytes 从按指定的列偏移量将字节流作为数组从给定的缓冲区偏移量开始读入缓冲区。 (覆盖 DbDataReader.GetBytes(Int32, Int64, array<Byte[], Int32, Int32)。)
公共方法 GetChar 在 SQL Server Compact 的 .NET Compact Framework 数据提供程序中不受支持。 (覆盖 DbDataReader.GetChar(Int32)。)
公共方法 GetChars 从指定的列偏移量将字符流作为数组从给定的缓冲区偏移量开始读入缓冲区。 (覆盖 DbDataReader.GetChars(Int32, Int64, array<Char[], Int32, Int32)。)
公共方法 GetData (继承自 DbDataReader
公共方法 GetDataTypeName 获取源数据类型的名称。 (覆盖 DbDataReader.GetDataTypeName(Int32)。)
公共方法 GetDateTime 获取指定列的 DateTime 对象形式的值。 (覆盖 DbDataReader.GetDateTime(Int32)。)
受保护方法 GetDbDataReader (继承自 DbDataReader
公共方法 GetDecimal 获取指定列的 Decimal 对象形式的值。 (覆盖 DbDataReader.GetDecimal(Int32)。)
公共方法 GetDouble 获取指定列的双精度浮点数形式的值。 (覆盖 DbDataReader.GetDouble(Int32)。)
公共方法 GetEnumerator 基础结构。 (覆盖 DbDataReader.GetEnumerator()。)
公共方法 GetFieldType 获取是对象的数据类型的 Type。 (覆盖 DbDataReader.GetFieldType(Int32)。)
公共方法 GetFloat 获取指定列的单精度浮点数形式的值。 (覆盖 DbDataReader.GetFloat(Int32)。)
公共方法 GetGuid 获取指定列的值作为全局唯一标识符 (GUID)。 (覆盖 DbDataReader.GetGuid(Int32)。)
公共方法 GetHashCode (继承自 Object
公共方法 GetInt16 获取指定列的 16 位有符号整数形式的值。 (覆盖 DbDataReader.GetInt16(Int32)。)
公共方法 GetInt32 获取指定列的 32 位有符号整数形式的值。 (覆盖 DbDataReader.GetInt32(Int32)。)
公共方法 GetInt64 获取指定列的 64 位有符号整数形式的值。 (覆盖 DbDataReader.GetInt64(Int32)。)
公共方法 GetLifetimeService (继承自 MarshalByRefObject
公共方法 GetName 获取指定列的名称。 (覆盖 DbDataReader.GetName(Int32)。)
公共方法 GetOrdinal 在给定列名称的情况下获取列序号。 (覆盖 DbDataReader.GetOrdinal(String)。)
公共方法 GetProviderSpecificFieldType 获取一个 Object,它表示基础提供程序特定的字段类型。 (覆盖 DbDataReader.GetProviderSpecificFieldType(Int32)。)
公共方法 GetProviderSpecificValue (继承自 DbDataReader
公共方法 GetProviderSpecificValues (继承自 DbDataReader
公共方法 GetSchemaTable 返回一个 DataTable,它描述 SqlCeDataReader 的列元数据。 (覆盖 DbDataReader.GetSchemaTable()。)
公共方法 GetSqlBinary 获取指定列的 SqlBinary 形式的值。
公共方法 GetSqlBoolean 获取指定列的 SqlBoolean 形式的值。
公共方法 GetSqlByte 获取指定列的 SqlByte 形式的值。
公共方法 GetSqlDateTime 获取指定列的 SqlDateTime 形式的值。
公共方法 GetSqlDecimal 获取指定列的 SqlDecimal 形式的值。
公共方法 GetSqlDouble 获取指定列的 SqlDouble 形式的值。
公共方法 GetSqlGuid 获取指定列的 SqlGuid 形式的值。
公共方法 GetSqlInt16 获取指定列的 SqlInt16 形式的值。
公共方法 GetSqlInt32 获取指定列的 SqlInt32 形式的值。
公共方法 GetSqlInt64 获取指定列的 SqlInt64 形式的值。
公共方法 GetSqlMoney 获取指定列的 SqlMoney 形式的值。
公共方法 GetSqlSingle 获取指定列的 SqlSingle 形式的值。
公共方法 GetSqlString 获取指定列的 SqlString 形式的值。
公共方法 GetString 获取指定列的字符串形式的值。 (覆盖 DbDataReader.GetString(Int32)。)
公共方法 GetType (继承自 Object
公共方法 GetValue 获取以本机格式表示的指定序号处的列的值。 (覆盖 DbDataReader.GetValue(Int32)。)
公共方法 GetValues 获取当前行中的所有属性列。 (覆盖 DbDataReader.GetValues(array<Object[])。)
公共方法 InitializeLifetimeService (继承自 MarshalByRefObject
受保护方法 IsCommandBehavior 确定指定的 CommandBehavior 是否匹配此 SqlCeDataReader。
公共方法 IsDBNull 获取一个值,用以表示列中是否包含不存在的或已丢失的值。 (覆盖 DbDataReader.IsDBNull(Int32)。)
受保护方法 MemberwiseClone() (继承自 Object
受保护方法 MemberwiseClone(Boolean) (继承自 MarshalByRefObject
公共方法 NextResult 在 SQL Server Compact 的 .NET Compact Framework 数据提供程序中不受支持。 (覆盖 DbDataReader.NextResult()。)
受保护方法 OnMove 基础结构。
公共方法 Read 将 SqlCeDataReader 移到下一个记录。 (覆盖 DbDataReader.Read()。)
公共方法 Seek 将 SqlCeDataReader 放置在包含与指定参数匹配的索引值的记录上。
公共方法 ToString (继承自 Object

页首

显式接口实现

  名称 说明
显式接口实现私有方法 IDataRecord.GetData (继承自 DbDataReader

页首

注释

若要创建 SqlCeDataReader,必须调用 SqlCeCommand 对象的 ExecuteReader 方法,而不直接使用构造函数。

当 SqlCeDataReader 处于使用状态时,关联的 SqlCeConnection 正忙于为 SqlCeDataReader 服务。在此状态下,可以在同一连接中创建多个读取器。

在读取数据时,SqlCeDataReader 的用户可以看到其他进程或线程对结果集所做的更改,具体情况取决于更改发生的时间。

当 SqlCeDataReader 关闭后,只能调用 IsClosed 属性和 RecordsAffected 属性。尽管当 SqlCeDataReader 存在时,可随时访问 RecordsAffected 属性,但是,请在返回 RecordsAffected 的值之前先调用 Close,以确保得到精确的返回值。

示例

下面的示例创建一个 SqlCeConnection、一个 SqlCeCommand 和一个 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();
}

线程安全

此类型的任何公共静态(在 Microsoft Visual Basic 中为共享)成员是线程安全的。不保证所有实例成员都对于线程安全的。

请参阅

参考

System.Data.SqlServerCe 命名空间