title: Visual Basic 9.0 does not support this kind of lambda expression
body: <p>I get this error <strong>"Visual Basic 9.0 does not support this kind of lambda expression"</strong> here " ExecuteWithinTransaction(<strong>Sub</strong>(con, trans) InsertA("Al", con, trans))" when i hover over the <strong>Sub</strong></p>
  
  <p>I am new to lambda expressions. Any help appreciated. I am using VS 2010 and .NET 3.5.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub Main() 
      ExecuteWithinTransaction(Sub(con, trans) InsertA("Al", con, trans))
      ExecuteWithinTransaction(Sub(con, trans) InsertB("Bert", con, trans))
  
      ExecuteWithinTransaction(Sub(con, trans)
                                   InsertA("Albert", con, trans)
                                   InsertB("Einstein", con, trans)
                               End Sub)
  End Sub
  
  ''' &lt;summary&gt;
  ''' Executes an action within a transaction. handles connection and transaction management
  ''' &lt;/summary&gt;
  ''' &lt;param name="action"&gt;The action to be executed&lt;/param&gt;
  Sub ExecuteWithinTransaction(ByVal action As Action(Of SqlConnection, SqlTransaction))
      Dim connection As SqlConnection = New SqlConnection("CONNECTIONSTRING")
  
      connection.Open()
      Try
          Dim transaction = connection.BeginTransaction()
  
          Try
              action(connection, transaction)
              transaction.Commit()
          Catch ex As Exception
              transaction.Rollback()
              Throw 'rethrow exception preserving original stacktrace
          End Try
      Finally
          connection.Close()
      End Try 
  End Sub
  
  Sub InsertA(ByVal name As String, ByVal connection As SqlConnection, ByVal transaction As SqlTransaction)
      Dim cmd As SqlCommand = New SqlCommand("INSERT INTO XXX (Name) VALUES (@NAME)", connection, transaction)
  
      cmd.Parameters.AddWithValue("@Name", name)
  
      cmd.ExecuteNonQuery()
  End Sub
  
  Sub InsertB(ByVal name As String, ByVal connection As SqlConnection, ByVal transaction As SqlTransaction)
      Dim cmd As SqlCommand = New SqlCommand("INSERT INTO YYY (Name) VALUES (@NAME)", connection, transaction)
  
      cmd.Parameters.AddWithValue("@Name", name)
  
      cmd.ExecuteNonQuery()
  End Sub
  </code></pre>