DataReaderExtensions.IsDBNullAsync(DbDataReader, String, CancellationToken) DataReaderExtensions.IsDBNullAsync(DbDataReader, String, CancellationToken) Method

定义

异步获取一个值,该值指示列中是否包含不存在的或缺少的值。Asynchronously gets a value that indicates whether the column contains non-existent or missing values.

public static System.Threading.Tasks.Task<bool> IsDBNullAsync (this System.Data.Common.DbDataReader reader, string name, System.Threading.CancellationToken cancellationToken = null);
static member IsDBNullAsync : System.Data.Common.DbDataReader * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>

参数

reader
DbDataReader DbDataReader

要从中获取列值的数据读取器。The data reader to get the column value from.

name
String String

列的名称。The name of the column.

cancellationToken
CancellationToken CancellationToken

用于取消异步操作的可选令牌。An optional token to cancel the asynchronous operation.

返回

一个 Task<TResult>,如果指定的列值等于 DBNull,则其 Result 属性为 true,如果不等于,则为 falseA Task<TResult> whose Result property is true if the specified column value is equivalent to DBNull or false if it is not.

异常

在数据检索期间删除或关闭连接。The connection was dropped or closed during the data retrieval.

-or-

在数据检索期间关闭数据读取器。The data reader is closed during the data retrieval.

-or-

没有要读取的就绪数据 (例如,第一个 Read() 未被调用或返回错误)。There is no data ready to be read (for example, the first Read() hasn't been called, or returned false).

- 或 --or-

按顺序模式尝试读取上一步骤中读取的列。Trying to read a previously read column in sequential mode.

- 或 --or- 没有正在进行的异步操作。There was an asynchronous operation in progress. 以顺序模式运行时,这适用于所有 Get* 方法,读取流时也可对其进行调用。This applies to all Get* methods when running in sequential mode, as they could be called while reading a stream.

指定的名称不是有效的列名。The name specified is not a valid column name.

注解

仅当在顺序模式下创建读取器时, 才需要此异步方法来避免阻塞调用线程。This asynchronous method is only needed to avoid blocking the calling thread when the reader is created in sequential mode.

如果未指定顺序模式, 则每次 ReadAsync 完成时, 所有列值都将在内存中可用, 并且调用该方法的同步版本不应阻止调用线程。If sequential mode isn't specified, all column values should become available in memory each time ReadAsync completes, and calling the synchronous version of the method shouldn't block the calling thread.

此异步方法的默认实现调用其同步对应项, 并返回已完成的任务, 可能会阻止调用线程。The default implementation of this asynchronous method invokes its synchronous counterpart and returns a completed Task, potentially blocking the calling thread. 如果传递了已取消的取消标记, 则默认实现还会返回已取消的任务。The default implementation also returns a cancelled task if passed an already cancelled cancellation token.

支持异步编程的数据访问接口应使用异步 i/o 操作来重写默认的 inmplementation。Data providers that support asynchronous programming should override the default inmplementation using asynchronous I/O operations.

该方法可用于请求操作之前接受取消标记。This method accepts a cancellation token that can be used to request the operation to be cancelled early. 实现可能会忽略该请求。Implementations may ignore this request.

当返回任务还未完成时, DbDataReader 对象的其他方法和属性不应调用 。Other methods and properties of the DbDataReader object should not be invoked while the returned Task is not yet completed.

适用于