⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtrans.frm

📁 ADOTrans.zip
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmTrans 
   Caption         =   "Transaction"
   ClientHeight    =   2205
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   2205
   ScaleWidth      =   4680
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtEditore 
      Height          =   285
      Left            =   1440
      TabIndex        =   2
      Top             =   840
      Width           =   3015
   End
   Begin VB.TextBox txtAutore 
      Height          =   285
      Left            =   1440
      TabIndex        =   1
      Top             =   360
      Width           =   3015
   End
   Begin VB.CommandButton cmdMakeChanges 
      Caption         =   "&change"
      Height          =   375
      Left            =   1680
      TabIndex        =   0
      Top             =   1560
      Width           =   1335
   End
   Begin VB.Label lblEditore 
      Caption         =   "Editore to delete:"
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   960
      Width           =   1215
   End
   Begin VB.Label lblAutore 
      Caption         =   "Auore to insert:"
      Height          =   255
      Left            =   120
      TabIndex        =   3
      Top             =   480
      Width           =   1095
   End
End
Attribute VB_Name = "frmTrans"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Author: Massimo Branca
'E-mail: massimobranca@hotmail.com
'URL   :http://www.geocities.com/calfinator3000
'The following code is intended for demonstration
'purpose only, so you can use it freely but at
'your own risk since this example program is
'provided "as is" with no warranty of any kind.
'Project > References > "Microsoft ActiveX data object 2.0 library
'This code has been made to work on a local unit.
'Change the code according to "LAN.txt" to make it work on a LAN.
'Purpose: Demonstrate ADO transactions (BeginTrans, Rollbacktrans, CommitTrans).
'         "Anything or nothing principle". If any error occurs making changes, all
'         changes are cancelled.
'         Imagine a transaction between to accounts in a bank. All changes are
'         confirmed only if  money is withdrawn from first account and deposited
'         on second account. If any error occur all changes are cancelled.
'         To test this program try to cancel a table in Pubblicazioni.mdb and watch.
'_____________________________________________________________________________________________

Private Sub cmdMakeChanges_Click()
'Declare and instantiate object variables.
Dim cnPubblicazioni As Connection
Dim sAutore As String
Dim sEditore As String

Set cnPubblicazioni = New Connection

'Establish a connection.
With cnPubblicazioni
     .Provider = "Microsoft.Jet.OLEDB.3.51"
     .ConnectionString = "Data Source=" & AppPath & "c:\Pubblicazioni.mdb;" & _
                         "Jet OLEDB:Database Password="
     .Open
End With

'Create connection between Strings and text boxes.
sAutore = txtAutore.Text
sEditore = txtEditore.Text

'A transaction space is created.
cnPubblicazioni.BeginTrans

'Turn on the error handler
On Error GoTo Error_handler

'SQL Commands are executed in the transaction.
cnPubblicazioni.Execute "INSERT INTO Autori(Autore) " & _
"VALUES ('" & sAutore & "')"
cnPubblicazioni.Execute "DELETE FROM Editori WHERE Editore = '" & sEditore & "'"

'If all commands are successfully, commit them
cnPubblicazioni.CommitTrans

'Close connection.
cnPubblicazioni.Close
Set cnPubblicazioni = Nothing
Exit Sub

Error_handler:
'If an error occured, roll back the changes.
cnPubblicazioni.RollbackTrans
MsgBox "An error occurred changing the records.", vbExclamation
End Sub

Private Sub Form_Unload(Cancel As Integer)
Unload Me
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -