Handling ExecuteScalar() when no results are returned

后端 未结 22 1078
猫巷女王i
猫巷女王i 2020-11-27 05:47

I am using the following SQL query and the ExecuteScalar() method to fetch data from an Oracle database:

sql = \"select username from usermst wh         


        
22条回答
  •  情深已故
    2020-11-27 06:33

    Slight conjecture: if you check the stack for the exception, it is being thrown then the ADO.NET provider for Oracle is reading the underlying rowset to get the first value.

    If there is no row, then there is no value to find.

    To handle this case execute for a reader and handle Next() returning false for the case of no match.

提交回复
热议问题