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. return value: Type: System.Object. if the first column of the first row in the result set is not found, a null reference is returned. If the value in the database is NULL, this query returns DBNull.Value. 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 the Result is DBNull or result = = DBNull.Value to judge. for the caller of the Dbcommand.executescalar method of ADO, be careful to choose whether to use result = = NULL based on the SQL statement being used or to use result is DBNull to determine if the query result is empty. if you use result = = NULL | | Result is DBNull to determine whether the query result is empty is more insurance, can adapt to the two kinds of SQL statements, but the efficiency of the operation will be reduced.
ExecuteScalar return value problem