rs.Open "select * from 白车身测量记录信息 where 导入文件名='" & filena & "'", conn, adOpenKeyset, adLockBatchOptimis这句主要用于判断数据是否已经存在,但假如不存在就查不到记录程序报错,如何获得出错信息而程序继续执行?
 If rs.RecordCount > 0 Then
            MsgBox "该文件数据已经存在数据库", vbOKOnly, "提示"
            Exit Sub
 End If

解决方案 »

  1.   

    set rs=cnn.execute("select * from 白车身测量记录信息 where 导入文件名='" & filena & "'")
    if not rs.bof then
        MsgBox "该文件数据已经存在数据库", vbOKOnly, "提示" 
        Exit Sub 
    end if
      

  2.   

    if rs.state<>adstateclosed then rs.close
    rs.Open "select * from 白车身测量记录信息 where 导入文件名='" & filena & "'", conn, adOpenKeyset,adlockreadonly
    if rs.recordcount>0 then
        msgbox "已存在!",48,"提示"
    else
        '不存在的处理语句
    end if
    rs.close
      

  3.   

    if rs.state<>adstateclosed then rs.close
    rs.Open "select * from 白车身测量记录信息 where 导入文件名='" & filena & "'", conn, adOenKeyset,adlockreadonly
    if rs.recordcont>0 then
        msgbox "已存在!",48,"提示"
    else
        '不存在的处理语句
    end if
    rs.closeup
      

  4.   

    或用select count(*), 判断 值。