Q:

Can I override SqlCommand functions?

I have code that will be for example
Dim cmd As New SqlClient.SqlCommand(commandString, databaseString) 
Dim result As Integer

Try
    result = cmd.ExecuteScalar()
Catch e as Exception
    'catch exception code
End Try

Instead of doing that, can I override the ExecuteScalar function to do some kind of generic exception catching?

A:

No, but you can create a generic DoExecuteScalar helper function that takes a SQL string and connection string:
Public Function DoExecuteScalar(commandString as String, databaseString as String) as Object
    Dim cmd as New SqlClient.SqlCommand(commandString, databaseString)
    Dim result as Integer
    Try
        result = cmd.ExecuteScalar()
    Catch e As Exception
        Return 0
    End Try
    Return result
End Function

