Short answer: the code below the return will never be executed.
This is like translated code. Like someone took a C # fragment from the Internet and tried to write it to VB for VS 2003 (before VB supported the USING statement, but while C # did).
where MySqlConnection and MySqlCommand are new, should be placed in USE blocks, and Dispose () lines converted to END USING.
If possible, use USING over TRY / FINALLY to ensure that IDisposable objects are cleaned.
using mySqlConnection as New SqlConnection(connectionString) mySqlConnection.Open using mySqlCommand as New SqlCommand(commandString, mySqlConnection) 'do something that may fail' return UserHasPermission end using 'disposes mySqlCommand' end using 'closes/disposes mySqlConnection'
You can also use this template for SqlTransactions. (Place after mySqlConnection.Open)
using myTerribleVariableName as SqlTransaction = mySqlConnection.BeginTransaction 'do something that may fail - multiple SqlCommands maybe' 'be sure to reference the transaction context in the SqlCommand' myTerribleVariableName.Commit end using 'disposes. rollsback if not commited'
Oh, and you can delete the RowCount = Nothing statement.
source share