Tutorials
ODP.NETTill now, we have seen OracleCommand working with OracleDataReader. OracleCommand is not simply meant for OracleDataReader. It has got a lot of functionality for itself. Let us see few of the most commonly used features of OracleCommand in this section. We will further go into depth in subsequent sections and chapters.
As we already covered working with single or multiple rows, we need to work on retrieving a single value from database very effectively. We have already retrieved row values in our previous examples, but those examples are more suitable when you are trying to deal with entire rows.
OracleCommand is equipped with a method called ExecuteScalar, which is mainly used to retrieve single values from the database very efficiently thus improving the performance. The following example focuses on this:
The highlighted line in the above code simply executes the SELECT command, which retrieves the number of rows from the emp table and assigns this value to the result variable.