请教各位
如何实现datagrid的批量更新
删除datagrid的当前记录

解决方案 »

  1.   

    Private Sub cmdCantactDelete_Click()
    '''On Error Resume Next
    Dim intYesNo As Integer       If dgAssetContact.SelBooks.Count = 0 Then
                MsgBox "请选择一条记录以供操作!"
                Exit Sub
           End If
           
             Set rs = New ADODB.Recordset
                  
            With rs
                 .CursorType = adOpenDynamic
                 .CursorLocation = adUseClient
                 .LockType = adLockPessimistic
                 .Source = "SELECT * FROM tblassetcontact WHERE serial ='" &Rst.Fields("serial").Value & "'"
            Set .ActiveConnection = cnnCMMS
                 .Open
            End With
        
        intYesNo = MsgBox("确实要删除这条参数吗?", vbYesNo)
        
        If intYesNo = vbYes Then
           Dim varBmk As Variant
           For Each varBmk In dgAssetContact.SelBooks
               rsContact.Book = varBmk
               rsContact.Delete
           Next
        End If
        
    End Sub
      

  2.   

    打开Rs使用adlockbatchoptimistic 批量更新模式工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)    Dim CN   As New ADODB.Connection                '定义数据库的连接
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"    CN.Open
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adlockbatchoptimistic
    删除:
           For Each Bmk In DataGrid1.SelBooks
               rs.Book = Bmk
               rs.Delete
           Next
    保存:
       Rs.update
       Rs.updatebatch
      

  3.   

    打开Rs使用adlockbatchoptimistic 批量更新模式工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)    Dim CN   As New ADODB.Connection                '定义数据库的连接
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"    CN.Open
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adlockbatchoptimistic
    删除:
           For Each Bmk In DataGrid1.SelBooks
               rs.Book = Bmk
               rs.Delete
           Next
    保存:
       Rs.update
       Rs.updatebatch
      

  4.   


    删除datagrid的当前记录也可使用:
        Rs.Delete adAffectCurrent
        Rs.Update
        Rs.UpdateBatch
        Rs.Requery