Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
执行 SQL SELECT 语句并返回单个值。
Public Overrides Function ExecuteScalar() As Object
public override object ExecuteScalar()
结果集中第一行的第一列,如果结果集为空,则为空值引用(在 Visual Basic 中是 Nothing)。
ULException 类 发生 SQL 错误。
InvalidOperationException 该命令处于无效状态。ULCommand.Connection 缺失或关闭、ULCommand.Transaction 值与连接的当前事务状态不匹配,或者 ULCommand.CommandText 无效。
该语句就是当前的 ULCommand 对象,它具有必需的 ULCommand.CommandText 和任何 ULCommand.Parameters。
如果在返回多个行和列的查询上调用该方法,则只会返回第一行的第一列。
如果 ULCommand.CommandType 为 System.Data.CommandType.TableDirect,则 ExecuteScalar 会执行 ULCommand.ExecuteTable() 并返回第一行的第一列。
出于性能原因,SELECT 语句在缺省情况下标记为只读。如果要将该查询用于执行更新,则此语句必须以 "FOR UPDATE" 作为结尾。