Handling ExecuteScalar() when no results are returned

后端 未结 22 1077
猫巷女王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:10

    I had this issue when the user connecting to the database had CONNECT permissions, but no permissions to read from the database. In my case, I could not even do something like this:

    object userNameObj = command.ExecuteScalar()

    Putting this in a try/catch (which you should probably be doing anyway) was the only way I could see to handle the insufficient permission issue.

提交回复
热议问题