SqlDataReader.GetChars 方法

从指定的列偏移量将字符流作为数组从给定的缓冲区偏移量开始读入缓冲区。

**命名空间:**System.Data.SqlClient
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public Overrides Function GetChars ( _
    i As Integer, _
    dataIndex As Long, _
    buffer As Char(), _
    bufferIndex As Integer, _
    length As Integer _
) As Long
用法
Dim instance As SqlDataReader
Dim i As Integer
Dim dataIndex As Long
Dim buffer As Char()
Dim bufferIndex As Integer
Dim length As Integer
Dim returnValue As Long

returnValue = instance.GetChars(i, dataIndex, buffer, bufferIndex, length)
public override long GetChars (
    int i,
    long dataIndex,
    char[] buffer,
    int bufferIndex,
    int length
)
public:
virtual long long GetChars (
    int i, 
    long long dataIndex, 
    array<wchar_t>^ buffer, 
    int bufferIndex, 
    int length
) override
public long GetChars (
    int i, 
    long dataIndex, 
    char[] buffer, 
    int bufferIndex, 
    int length
)
public override function GetChars (
    i : int, 
    dataIndex : long, 
    buffer : char[], 
    bufferIndex : int, 
    length : int
) : long

参数

  • i
    从零开始的列序号。
  • dataIndex
    字段中的索引,从其开始读取操作。
  • buffer
    要将字节流读入的缓冲区。
  • bufferIndex
    开始写操作的 buffer 的索引。
  • length
    要复制到缓冲区中的最大长度。

返回值

读取的实际字符数。

备注

GetChars 返回字段中可用字符的数目。通常情况下,这是字段的准确长度。但是,如果 GetChars 已用于从字段中获取字符,则返回的数字可能会小于字段的真实长度。例如,如果 SqlDataReader 正在将一个大型数据结构读入缓冲区,则可能出现这种情况。有关更多信息,请参见 CommandBehaviorSequentialAccess 设置。

读取的实际字符数可以小于请求的长度,如果已到达字段的结尾。如果传递为 空引用(在 Visual Basic 中为 Nothing) 的缓冲区,则 GetChars 以字符为单位返回整个字段的长度,而不是基于缓冲区偏移量参数的剩余大小。

不执行任何转换,因此所检索的数据必须已经是字符数组。

提示

如果 CommandBehavior 设置为 SequentialAccess,则不能使用 GetChars 读取块区中的 VarChar 列。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

SqlDataReader 类
SqlDataReader 成员
System.Data.SqlClient 命名空间

其他资源

在 ADO.NET 中连接和检索数据
使用 SQL Server .NET Framework 数据提供程序