我有一个程序可以在 2 个查询中将记录插入数据库。我正在那里处理事务。但是我的交易不起作用。执行第一条语句后,如果我关闭程序记录将插入第一个表而不插入第二个表。
但这应该从第一个表回滚。这里有什么问题。
Try
objBLlCommonFunction.BeginTransaction()
For j As Integer = 0 To dgstkReceivd.VisibleRowCount - 1
objBllStcTransaction.InsertStockTransferExcelDetail(InvNo, lblDateI.Text)
Next
objBllStcTransaction.InsertStockTransferExcelHeader(InvNo, dbId)
ScriptManager.RegisterClientScriptBlock(btnSave, btnSave.GetType(), "message", "alert('" + "Successfully Saved" + "');", True)
objBLlCommonFunction.CommitTransaction()
Catch ex As Exception
objBLlCommonFunction.RollbackTransaction()
objerror.AddToErrorLog(ex.StackTrace, ex.Message)
ScriptManager.RegisterClientScriptBlock(btnSave, btnSave.GetType(), "message", "alert('" + ex.Message + "');", True)
End Try