Pregunta

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

¿Fue útil?

Solución

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 ...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top