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 cursor2FETCH  NEXT from cursor1
endclose cursor1
--不知道对你有用否?

解决方案 »

  1.   

    谢谢你,不过我在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()
    //////////////////////////////////////////////
    假设有两段同样的事务,我怎样把它们嵌套起来,因为如果前者执行了,后者出错,则需要前者也回滚。帮我想想办法。
      

  2.   

    昨晚我试了终于有结果了,现作出说明,以便大家参考
    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(),在这期间如果有一个事务回滚,则所有的事务都回滚。也就意味着,要不都提交,要不都回滚。这一点在实际应用中很广泛。