About Command.executeScalar Return Value

zhaozj2021-02-16  77

Command.executeScale () typically returns the Object type, but we often convert it into a corresponding database field type. For example, Oracle Database Field Type is Numeric, with int result = (int) Command.executeScale (); will trigger InvalidCastException. There are two methods at this time:

1. Use int results = int.parse (Command.executeScale (). TOSTRING ());

2. Change to Decimal, Decimal Result = (Decimal) Command.executeScale ();

Obvious method 2 is better than method 1.

Sometimes ExecuteScale () returns NULL, you can write the corresponding code with Catch (NullReferenceException).

转载请注明原文地址:https://www.9cbs.com/read-14908.html

New Post(0)