国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

docmd.runsql 語句執行的操作查詢如何回滾?

2024-07-21 02:08:15
字體:
來源:轉載
供稿:網友

docmd.runsql 語句執行的操作查詢如何回滾?
 
 
簡述:docmd.runsql 語句執行的操作查詢如何回滾?
 

 

問題:

docmd.runsql 語句執行的操作查詢如何回滾?
 



回答:

希望通過docmd.runsql實現事務的回滾(rollback)操作


很遺憾的說,access無法法通過docmd.runsql來實現事務的回觥4蠹乙殘磣⒁獾皆贒ocmd.runsql的語句操作的幫助中,有一個選項是usetransaction。這個選項的是用來確認是否對該語句進行事務性的操作。如果選擇true(默認為true),那么所有的操作都將被當作是一個單獨的原子操作來對數據庫進行操作;如果選擇是false,那么操作將不會被當作事務(在多用戶的情況下可能會出現dirty read)的情況。但是這些事務都是在內部完成的,我們無法顯示的通過申明commit或者rollback來控制其操作。

根據我的經驗,access也無法通過docmd.openquery來完成類似的事務顯示操作。如果大家希望實現事務的操作,唯一的用法就是通過workspaceobject.begintrans來實現。在access vba的幫助文件中,大家可以找到如下的示例:
'beginbegintransvb


    'to integrate this code
    'replace the data source and initial catalog values
    'in the connection string
    
public sub main()
    on error goto errorhandler

    'recordset and connection variables
    dim cnxn as adodb.connection
    dim strcnxn as string
    dim rsttitles as adodb.recordset
    dim strsqltitles as string
    'record variables
    dim strtitle as string
    dim strmessage as string
    
    ' open connection
    strcnxn = "provider='sqloledb';data source='mysqlserver';" & _
        "initial catalog='pubs';integrated security='sspi';"
    set cnxn = new adodb.connection
    cnxn.open strcnxn
    
    ' open recordset dynamic to allow for changes
    set rsttitles = new adodb.recordset
    strsqltitles = "titles"
    rsttitles.open strsqltitles, cnxn, adopendynamic, adlockpessimistic, adcmdtable
    
    cnxn.begintrans
    
    ' loop through recordset and prompt user
    ' to change the type for a specified title
    
    rsttitles.movefirst
    
    do until rsttitles.eof
        if trim(rsttitles!type) = "psychology" then
            strtitle = rsttitles!title
            strmessage = "title: " & strtitle & vbcr & _
            "change type to self help?"

            ' if yes, change type for the specified title
            if msgbox(strmessage, vbyesno) = vbyes then
                rsttitles!type = "self_help"
                rsttitles.update
            end if
        end if
    rsttitles.movenext
    loop

    ' prompt user to commit all changes made
    if msgbox("save all changes?", vbyesno) = vbyes then
        cnxn.committrans
    else
        cnxn.rollbacktrans
    end if

    ' print recordset
    rsttitles.requery
    rsttitles.movefirst
    do while not rsttitles.eof
        debug.print rsttitles!title & " - " & rsttitles!type
        rsttitles.movenext
    loop

    ' restore original data as this is a demo
    rsttitles.movefirst
    
    do until rsttitles.eof
        if trim(rsttitles!type) = "self_help" then
            rsttitles!type = "psychology"
            rsttitles.update
        end if
        rsttitles.movenext
    loop
   
    ' clean up
    rsttitles.close
    cnxn.close
    set rsttitles = nothing
    set cnxn = nothing
    exit sub
    
errorhandler:
    ' clean up
    if not rsttitles is nothing then
        if rsttitles.state = adstateopen then rsttitles.close
    end if
    set rsttitles = nothing
    
    if not cnxn is nothing then
        if cnxn.state = adstateopen then cnxn.close
    end if
    set cnxn = nothing
    
    if err <> 0 then
        msgbox err.source & "-->" & err.description, , "error"
    end if
end sub


'endbegintransvb



最后,強烈推薦大家閱讀下列文檔,在文檔有一個章節:transactions在access中的用法和定義
advanced microsoft jet sql for access 2000
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acadvsql.asp

另外,請參考本站的文章:

關于事務處理
http://access911.net/index.asp?u1=a&u2=73fabf1e14dc

什么是事務處理?怎么進行事務處理?
http://access911.net/index.asp?u1=a&u2=71fabe1e13dc
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新乡县| 北安市| 自贡市| 文化| 宁德市| 北安市| 乌鲁木齐县| 汝城县| 正镶白旗| 新疆| 白银市| 衡水市| 西吉县| 珠海市| 湖南省| 衡南县| 贺州市| 南充市| 岳池县| 迁西县| 鸡东县| 宜章县| 偃师市| 墨竹工卡县| 砚山县| 安岳县| 米脂县| 赞皇县| 夏河县| 巴塘县| 浮梁县| 永清县| 新化县| 景德镇市| 双鸭山市| 黑龙江省| 罗平县| 永登县| 翼城县| 托克逊县| 元朗区|