ExecuteScalar return value problem
Dbcommand.executescalar Method:
Executes the query and returns the first column of the first row in the result set returned by the query. All other columns rows will be ignored.
Syntax: Public abstract Object ExecuteScalar ()
Return value: Type: System.Object, the first column of the first row in the result set.
Note: Use the ExecuteScalar method to retrieve a single value (such as an aggregated value) from the database. With the use of ExecuteReader Party
The method then uses the data returned by DbDataReader to perform the actions required to generate a single value, which requires less code than the operation. If you do not find
To the first column of the first row in the result set, a null reference (Nothing in Visual Basic) is returned. If the database in the
Value is NULL, this query returns DBNull.Value.
For querying a single field, do not include the function's SELECT statement, for example, the Select a field from Table A, if no value exists,
The return value of the Dbcommand.executescalar method is null, and the caller needs to be judged using result = = null.
For SELECT statements that use functions, such as select sum (a field) from table A, if no value exists,
The return value of the Dbcommand.exceutescalar method is DBNull.Value, and the caller needs to use result is DBNull or result
= = DBNull.Value to judge.
For the caller of the Dbcommand.executescalar method of ADO, pay attention to the use of the SQL statement used to select the
result = = NULL or use result is DBNull to determine whether the query result is empty. If you use result = = NULL | |
Result is DBNull to determine whether the query result is empty and is more safe to adapt to the two SQL statements, but the efficiency of the operation
will be reduced.
ExecuteScalar return value problem