Dim rs as adodb.recordset, rsTmp as adodb.recordset
rs.open "select * from objTable", adoCon,adOpenstatic,adlockreadOnly _
adCmdText
debug.print rs.recordcount 'rs.recordset=100
dim i as interger , j as interger
randomize=timer
for i=1 to 50
    rs.absoluteposition = int((100-1+1)*rnd+1))
    rsTmp.addNew
    for j=0 to rs.field.count-1
        rsTmp(j).value=rs(j).value
    next   
next
这段程序就是从一个rs里随机抽取50个记录送入 rsTmp里,问题是出现了惨痛的错误

解决方案 »

  1.   

    这些错误是rsTmp 说没有打开不能用 addNew 方法。rsTmp里本来就没东西是我用来放50个随机数据的地方。于是我就这样做了一下
    首先 rsTmp.open "select top 1 * from objTable",adoCon,adOpenStatic,_
                    adLockReadOlny,adCmdText
         debug.print rsTmp.recordCount 'rsTmp.recordcount =1
         rsTmp.delete 
         rsTmp.movefirst
         再接下来就是原来的操作。addNew 方法可用了现在又出现悲痛的错误 rsTmp.update 说不能更新 我的 本来的意思就是rsTmp的更改不要影响数据库里的数据。现在它又哽屁了在upDate方法上。苦恼。缠绵.........
     等待高手现身。请帮我我解决这个问题如何把50个指定数据送入一个临时不影响数据库里数据的rsTmp里          
      

  2.   

    adlockreadOnly,i think.msdn:Enumeration Value Description 
    adLockUnspecified -1 Indicates an unspecified value for the LockType (not supported by the OLE DB Provider for AS/400 and VSAM). 
    adLockReadOnly 1 Specifying this value opens a Recordset object read-only and data cannot be altered.  
    adLockPessimistic 2 Specifying this value opens a recordset with pessimistic locking. Record-by-record, the OLE DB Provider does whatever is necessary to ensure successful editing of the records, usually by locking records at the data source immediately upon editing. 
    adLockOptimistic 3 Specifying this value opens a recordset with optimistic locking. Record-by-record, the OLE DB Provider locks records only when the Update method is invoked on a Recordset object. 
    adLockBatchOptimistic 4 Specifying this value opens a Recordset with batch optimistic locking. This value is required for batch update mode as opposed to immediate update.  
      

  3.   

    数据源是否是可更新的取决于数据供应程序。例如,如果某个数据源是一个由于LockType属性被设置为adLockReadOnly而打开的ADO记录集,那么,该数据源就不能更新。