如果没从数据库中检出记录怎么办Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordsetcn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\ DB1.MDB;Persist Security Info=False"
cn.Openrs.CursorLocation = adUseClient
sql = "select  *  from  pas  where  id  =  '  " & Trim(ID) & "'  "
rs.Open sql, cn, adOpenDynamicLabel3.Caption = rs(1) 如果一切顺利那没问题,那如果数据库中没有符合条件记录,在Label3.Caption = rs(1) 
处就会有问题。而又不能用rs(1)=””来判断,用isnull(rs(1))也不行
这个地方应该怎么判断呢

解决方案 »

  1.   

    rs.CursorLocation = adUseClient
    sql = "select  *  from  pas  where  id  =  '  " & Trim(ID) & "'  "
    rs.Open sql, cn, adOpenDynamic
    if not rs.eof then
    Label3.Caption = rs(1) 
    else
    msgbox "没有纪录"
    end if
      

  2.   

    If rs.EOF = True Then
      MsgBox "没有符合条件的记录"
      Exit Sub
    Else
      label1.Caption = rs.Fields(1)
    End If
      

  3.   

    if rs.RecordCount>0 then
        label1.Caption = rs.Fields(1)end if
      

  4.   

    if rs.bof and rs.eof then
       msgbox "没有记录"
    else
       rs.movelast
       msgbox "有" & rs.recordcount & "条记录!"
    end if