VB.Net by API/System.Data.SqlClient/SqlTransaction — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
SqlTransaction.BeginTransaction()
Imports System
Imports System.Data
Imports System.Data.SqlClient
public class MainClass
Shared Sub Main()
Dim myconnection As SqlConnection
Dim mycommand As SqlCommand
Dim mytransaction As SqlTransaction
Dim ConnectionString As String
myconnection = New SqlConnection("server=(local)\SQLEXPRESS;" & _
"integrated security=sspi;database=MyDatabase")
myconnection.Open()
mytransaction = myconnection.BeginTransaction()
mycommand = New SqlCommand
mycommand.Connection = myconnection
mycommand.Transaction = mytransaction
Try
mycommand.rumandText = "insert into Employee(ID," & _
"FirstName,LastName) values(119, " & _
""F","L")"
mycommand.ExecuteNonQuery()
mytransaction.Rollback()
Console.WriteLine("Rollback()")
mycommand.rumandText = "insert into Employee(ID," & _
"FirstName,LastName) values(119, " & _
""F","L")"
mytransaction.rumit()
Catch e As Exception
Console.WriteLine(e.Message)
Finally
myconnection.Close()
End Try
End Sub
End Class