亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        ASP:隨機訪問Recordset的一條記錄

        字號:


            假設(shè)這個數(shù)據(jù)表有一個唯一的ID字段,并至少有一條記錄。隨機存取其中一條記錄的方法是非常簡單的,可以分為四步:
            1、取得記錄總數(shù)n。
            2、把所有的ID號存儲到一個數(shù)組中
            3、產(chǎn)生一個不大于n的隨機數(shù)m
            4、從數(shù)組中取出第m個ID號,查詢數(shù)據(jù)表,取得記錄數(shù)據(jù)。
            下面是部分代碼:
            set conn = Server.CreateObject(‘ADODB.Connection‘)
            conn.open ;‘
            ‘ ***** (step 1) *****
            set rs = conn.execute(‘Select count(id) from someTable‘)
            rCount = rs(0)
            ‘ ***** (step 2) *****
            set rs = conn.execute(“select id from someTable”)
            cnt = 1
            dim RRs
            redim RRs(rCount)
            do while not rs.eof
            RRs(cnt) = rs(0)
            cnt = cnt + 1
            rs.movenext
            loop
            ‘ ***** (step 3) *****
            randomize
            currentRR = cLng(rnd*rCount+0.5)
            ID = RRs(currentRR)
            ‘ ***** (step 4) *****
            sql = “select otherfield from someTable where id=” & ID
            set rs = conn.execute(sql)
            response.write “ID # ” & ID & “ = ” & rs(0)
            rs.close: set rs = nothing
            conn.close: set conn = nothing
            ;
            對于SQL Server,還有更加有效率的方法。比如設(shè)計兩個存儲過程。我這里只是闡明一些思路,并希望這種思路可以同時用在Access和SQL Server中。