CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2001
    Posts
    7

    How to judge whether a Recordset are Null or not

    My code is like
    Dim conn As ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sSQL As String
    'gSession.GetConn will open connection
    Set conn = gSession.GetConn

    For i = 1 To 12

    strDateTo = frmChart.txtDate(4) & "/" & frmChart.txtDate(3) & "/" & frmChart.txtDate(5)
    strDateFrom = frmChart.txtDate(1) & "/" & frmChart.txtDate(0) & "/" & frmChart.txtDate(2)
    sSQL = "SELECT * FROM TestResult WHERE TestResult.Handset_Model = '" & strHandsetModel & "'"
    sSQL = sSQL & " AND TestResult.Date_Time <= #"
    sSQL = sSQL & strDateTo & "#"
    sSQL = sSQL & " AND TestResult.Date_Time >= #"
    sSQL = sSQL & strDateFrom & "#"
    sSQL = sSQL & " AND Code = " & i
    sSQL = sSQL & " ORDER BY Date_Time"

    rs.Open sSQL, conn, adOpenStatic, adLockReadOnly
    ' If rs = Null Then Debug.Print "Good"
    While Not rs.EOF
    Debug.Print rs!Handset_Model, rs!Date_Time, rs!Code
    'monthTestFrom = Month(dateTestFrom)
    intMonth = (Month(rs!Date_Time) - Month(dateTestFrom)) + 1 + (Year(rs!Date_Time) - Year(dateTestFrom)) * 12
    arrStat(intMonth, i + 1) = arrStat(intMonth, i + 1) + 1
    rs.MoveNext
    Wend
    rs.Close
    Next i

    at first I want to compare rs.RecordCount to zero to decide if the recordset is null but seems does not work. Even there is nothing inside the recordset the RecordCount still = 1

    if there is nothing in the rs, i will have prolem with my while loop. would u please tell me how to sort out this problem. email [email protected]

    tks a lot


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: How to judge whether a Recordset are Null or not

    Replace

    ' If rs = null then Debug.print "Good"



    with

    If (rs.BOF And rs.EOF) then Debug.print "Good"



    as this can only be true if RS has no records.

    HTH,
    D

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How to judge whether a Recordset are Null or not

    If Not IsNull(rs.Field(0)) then Debug.print "Good"


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: How to judge whether a Recordset are Null or not

    If not rs.EOF and rs.BOF then debug.print "Good"

    David Paulson

  5. #5
    Join Date
    Jul 2001
    Posts
    5

    Re: How to judge whether a Recordset are Null or not

    Its enough to just:
    if rs.eof then
    do nothing
    else
    Do until rs.eof
    bla
    loop
    end if


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured