畅享博客 > 蓝色梦想 > 信息技术 > [转帖]_delete 方法范例 (VB)
2007-3-6 20:14:19

[转帖]_delete 方法范例 (VB)

_delete 方法范例 (VB)

本范例使用 _delete 方法从 Recordset 删除指定的记录。

Public Sub _deleteX()

    Dim rstRoySched As ADODB.Recordset
    Dim strCnn As String
    Dim strMsg As String
    Dim strTitleID As String
    Dim intLoRange As Integer
    Dim intHiRange As Integer
    Dim intRoyalty As Integer

    ’ Open RoySched table.
        strCnn = "Provider=sqloledb;" & _
        "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
    Set rstRoySched = New ADODB.Recordset
    rstRoySched.CursorLocation = adUseClient
    rstRoySched.CursorType = adOpenStatic
    rstRoySched.LockType = adLockBatchOptimistic
    rstRoySched.Open "select * FROM roysched " & _
        "WHERE royalty = 20", strCnn, , , adCmdText

    ’ Prompt for a record to _delete.
    strMsg = "Before _delete there are " & _
        rstRoySched.RecordCount & _
        " titles with 20 percent royalty:" & vbCr & vbCr
    Do While Not rstRoySched.EOF
        strMsg = strMsg & rstRoySched!title_id & vbCr
        rstRoySched.MoveNext
    Loop
    strMsg = strMsg & vbCr & vbCr & _
        "Enter the ID of a record to _delete:"
    strTitleID = UCase(InputBox(strMsg))

    ’ Move to the record and save data so it can be restored.
    rstRoySched.Filter = "title_id = ’" & strTitleID & "’"
    intLoRange = rstRoySched!lorange
    intHiRange = rstRoySched!hirange
    intRoyalty = rstRoySched!royalty

    ’ _delete the record.
    rstRoySched._delete
    rstRoySched._updateBatch

    ’ Show the results.
    rstRoySched.Filter = adFilterNone
    rstRoySched.Requery
    strMsg = ""
    strMsg = "After _delete there are " & _
        rstRoySched.RecordCount & _
        " titles with 20 percent royalty:" & vbCr & vbCr
    Do While Not rstRoySched.EOF
        strMsg = strMsg & rstRoySched!title_id & vbCr
        rstRoySched.MoveNext
    Loop
    MsgBox strMsg

    ’ Restore the data because this is a demonstration.
    rstRoySched.AddNew
    rstRoySched!title_id = strTitleID
    rstRoySched!lorange = intLoRange
    rstRoySched!hirange = intHiRange
    rstRoySched!royalty = intRoyalty
    rstRoySched._updateBatch

    rstRoySched.Close

End Sub

推荐到鲜果: 查阅更多相关主题的帖子: _delete 方法范例 (VB)

评论

您正在以 匿名用户 的身份发表评论  快速登录
(不得超过 50 个汉字)
       看不清,换一个
提示消息
(输入完内容可以直接按Ctrl+Enter提交)