我想做两种方法,一种是只插入一个寄存器,另一种是插入多个寄存器(一个列表)。
但我希望第二种方法调用第一种方法,只是为了使用相同的 INSERT 代码。
有没有办法使用在第二种方法中打开的连接,在第一种方法中,所以我可以为所有人调用回滚?
Shared Sub Gravar(ByRef Pessoa As Pessoa)
Try
Using con As New myConnection
con.Open()
If Pessoa.Id = -1 Then
Insert(Pessoa, con)
Else
Update(Pessoa, con)
End If
End Using
Catch ex As Exception
Throw
End Try
End Sub
Shared Sub Gravar(ByRef Pessoas As List(Of Pessoa))
Try
Using con As New myConnection
con.Open()
con.OpenTransaction()
For Each Pessoa As Pessoa In Pessoas
Gravar(Pessoa)
Next
con.Commit()
End Using
Catch ex As Exception
Throw
End Try
End Sub
谢谢