我得到這個錯誤「的Visual Basic 9.0不支持這種lambda表達式的」這裏 「ExecuteWithinTransaction(子(CON,反式)INSERTA(」 基地」 ,con,trans))「當我將鼠標懸停在時Sub的Visual Basic 9.0不支持這種lambda表達式的
我是lambda表達式的新手。任何幫助讚賞。我正在使用VS 2010和.NET 3.5。
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
''' <summary>
''' Executes an action within a transaction. handles connection and transaction management
''' </summary>
''' <param name="action">The action to be executed</param>
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
爲什麼使用.NET 3.5 VS 2010中? –
@TimSchmelter有不同的開發人員在同一個項目上工作,每個人都沒有VS 2010. – Monodeep