Domanda

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

È stato utile?

Soluzione

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 ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top