例如
Adodc1.LockType=adLockBatchOptimistic 
Adodc1.RecordSource = "SELECT * FROM T1,T2 WHERE T1.ID=T2.ID"
Adodc1.Recordset.Delete
Adodc1.Recordset.UpdateBatch总是报错:“缺少更新或刷新的键列信息。”
应该怎样解决?

解决方案 »

  1.   

    Adodc1.Recordset.Delete
    if adodc1.recordset.EOF then
       adodc1.recordset.movelast
    else
       adodc1.movenext
    end if
      

  2.   

    adodc1.movenext
    改为adodc1.recordset.movenext
      

  3.   

    改了也不行报错是
    Adodc1.Recordset.UpdateBatch
    这行报的
      

  4.   

    原因出在,你的查询的结果记录集是两个表的矢量积中的符合条件的记录,既不能确定是T1的也不能确定是T2的。解决办法是指定连接类型为内连接(INNER join)——这样也执行的更快。
      select * from T1 inner join T2 on T1.ID=T2.ID
                    ~~            ~~
                    这里要看你决定哪个表是主表,也就是你要执行删除动作的表。
      

  5.   

    写代码分别删除两个表中的对应记录(适于一对多的主细级联删除):
    Adodc1.RecordSource = "SELECT * FROM T1,T2 WHERE T1.ID=T2.ID"
    ......dim myID 
    dim cn as new adodb.connectionmyID = adodc1.recordset.Fields("T1.ID")
    cn.open adodc1.connectionstring
    cn.execute "delete from T1 where ID=" & myID
    cn.execute "delete from T2 where ID=" & myID
    cn.close
    set cn = nothing