大家好,我有一個典形的事務處理如下,請看看有什麼問題,是不是這樣就會產生死鎖?<br>代碼我是用VB的。但SQL一樣。<br>On Error GoTo Err_確認出倉_Click:<br> Dim Oqty As Single<br> Dim Mconn As ADODB.Connection<br> Set Mconn = CurrentProject.Connection<br><br> Dim StrOne As ADODB.Command<br> Set StrOne = New ADODB.Command<br> StrOne.ActiveConnection = Mconn<br> StrOne.CommandType = adCmdText<br> <br> Dim StrTwo As ADODB.Command<br> Set StrTwo = New ADODB.Command<br> StrTwo.ActiveConnection = Mconn<br> StrTwo.CommandType = adCmdText<br> Dim StrThree As ADODB.Command<br> Set StrThree = New ADODB.Command<br> StrThree.ActiveConnection = Mconn<br> StrThree.CommandType = adCmdText<br>Mconn.BeginTrans<br> <br> StrOne.CommandText = "INSERT INTO BOM發料記錄表 (計劃單號,發貨單編號,部件型號,發貨數量,日期,出倉標記,備注)" & _<br> "VALUES ('" & Me.計劃單號 & "','" & Me.出倉單編號 & "','" & Me.部件型號 & "','" & Me.數量 & "','" & Date & "','" & Me.出倉標記 & "','" & Me.備注 & "');"<br> <br> StrTwo.CommandText = "UPDATE 噴油加工計劃表 " & _<br> "SET 噴油加工計劃表.領料數量 = [領料數量] + " & Me.數量 & _<br> "WHERE (((噴油加工計劃表.計劃單號)='" & Me.計劃單號 & "') and ((噴油加工計劃表.部件型號)='" & Me.部件型號 & "') and ((噴油加工計劃表.顏色)='" & Me.顏色 & "'));"<br> <br> StrThree.CommandText = "UPDATE 部件表 " & _<br> "SET 部件表.庫存量=部件表.庫存量 - " & Me.數量 & ", 部件表.噴油加工數 = 部件表.噴油加工數 +" & Me.數量 & " " & _<br> "WHERE 部件表.部件型號= '" & Me.部件型號 & "';"<br><br> StrOne.Execute<br> StrTwo.Execute<br> StrThree.Execute<br> Mconn.CommitTrans<br> Set StrOne = Nothing<br> Set StrTwo = Nothing<br> Set StrThree = Nothing<br>MsgBox " OK" <br>End If<br>Exit Sub<br><br>Err_確認出倉_Click:<br> Mconn.RollbackTrans<br> MsgBox " 進倉出錯,請關閉程序再重試! "<br> Set StrOne = Nothing<br> Set StrTwo = Nothing<br> Set StrThree = Nothing