ADBlock is blocking some content on the site

ADBlock errore

Ado.Net - Return true or false from ExecuteScalar and ExecuteNonQuery

StackOverflow https://stackoverflow.com/questions/13216745


I'm new to dotnet, can anyone please help.

What we require is to return status true or false when we run ExecuteScalar or ExecuteNonquery ado commands in our vb.net code.



Simply write an extension method for SQLCommand wrapping the original functionality.

Public Function MyExecuteScalar(ByVal sqlCommand As SqlCommand) As Boolean
    MyExecuteScalar = Not (sqlCommand.ExecuteScalar() is Nothing)
End Function

Public Function MyExecuteNonQuery(ByVal sqlCommand As SqlCommand) As Boolean
    MyExecuteNonQuery = sqlCommand.ExecuteNonQuery() > 0
End Function

Call these methods simply like this:

if mySqlCommand.MyExecutescalar() then ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow