Question

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.

Regards

Était-ce utile?

La solution

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

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

<Extension()> 
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 ...
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top