关于嵌套事务的问题,具体如何实现?

developerworks 2003-03-06 04:40:01
关于嵌套事务的问题,具体如何实现?帮忙给点意见!
...全文
147 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
link800 2003-03-07
  • 打赏
  • 举报
回复
学习
developerworks 2003-03-07
  • 打赏
  • 举报
回复
昨晚我试了终于有结果了,现作出说明,以便大家参考
vb.net+sqlserver2000
------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sSql, sSql1 As String
Dim myCommand As SqlCommand

sSql = "update person set personName='00111'"


ShiWuKS()
''''''''''''''''''''''''''''''''''''''''''''''''
If ZhiXingSQL(sSql) = False Then
ShiWuHJ()
Else
If xx() = False Then
MessageBox.Show("不成功")
Exit Sub
End If
If yy() = False Then
MessageBox.Show("不成功")
Exit Sub
End If
''''''''''''''''''''''''''''''''''''''''''''''''
ShiWuWC()
MessageBox.Show("更新成功")
End If

End Sub

Public Function xx() As Boolean
'''''''''''''''''''''''''''''''''''
Dim sSql1 As String
ShiWuKS()
sSql1 = "insert into material values('1003','cl0001')"
If ZhiXingSQL(sSql1) = False Then
ShiWuHJ()
xx = False
Exit Function
Else
xx = True
ShiWuWC() '''''''''''''''''''''''''''''''
End If
End Function

Public Function yy() As Boolean
'''''''''''''''''''''''''''''''''''
Dim sSql1 As String
ShiWuKS()
sSql1 = "inser into material values('1004','cl0001')"'假设这是一条出错的语句
If ZhiXingSQL(sSql1) = False Then
ShiWuHJ()
yy = False
Exit Function
Else
yy = True
ShiWuWC() '''''''''''''''''''''''''''''''
End If
End Function
------------------------------------------
在botton1按钮按下时,首先执行"update person set personName='00111'",如果正确无误,就执行xx() 过程,然后yy(),在这期间如果有一个事务回滚,则所有的事务都回滚。也就意味着,要不都提交,要不都回滚。这一点在实际应用中很广泛。
4czh 2003-03-06
  • 打赏
  • 举报
回复
无法嵌套事物
developerworks 2003-03-06
  • 打赏
  • 举报
回复
谢谢你,不过我在ado.net中没用存储过程来做
1//////////////////////////////////////////////
SQLs = Nothing
SQLs = ShuJu.ChuangJianSQL("插入")
'事务处理开始
cShuJuK.ShiWuKS()
For i = 1 To SQLs.Count
'执行SQL语句,如果有错,回滚事务
If cShuJuK.ZhiXingSQL(SQLs(i)) = False Then
cShuJuK.ShiWuHJ()
Exit Function
End If
Next
'提交事务
ChaRu = True
cShuJuK.ShiWuWC()
//////////////////////////////////////////////
假设有两段同样的事务,我怎样把它们嵌套起来,因为如果前者执行了,后者出错,则需要前者也回滚。帮我想想办法。
psxfghost 2003-03-06
  • 打赏
  • 举报
回复
DECLARE cursor1 CURSOR FOR select * from NorthWind..Customers
OPEN cursor1
FETCH NEXT from cursor1
WHILE @@FETCH_STATUS = 0
begin
DECLARE cursor2 CURSOR FOR select * from NorthWind..Customers
OPEN cursor2
FETCH NEXT from cursor2
WHILE @@FETCH_STATUS = 0
begin
FETCH NEXT from cursor2

end
close cursor2
DEALLOCATE cursor2

FETCH NEXT from cursor1
end

close cursor1
--不知道对你有用否?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧