Results 1 to 8 of 8

Thread: Return Value

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Return Value

    Hi

    I have written this code , it is giving me value -1 . Table has no record , it should not give 0 if no record exists.

    rscompany.Open "select * from owner", cnn1, adOpenDynamic, adLockOptimistic, adCmdText

    I am using SQL Database.

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Return Value

    That line of code doesn't give a value, I presume you are using other code too which does.

    Also, "SQL Database" is not descriptive enough... there are hundreds of database systems which use SQL, dozens of which have SQL as part of their name (MySQL, SQL Server, ...), and each of those has multiple versions.

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Return Value

    You don't say where you are seeing the -1. I guessing it is rscompany.RecoredCount. I think getting that to populate with zero depends on your cursor options. Using these I get a recordcount of zero. I freely admit I don't understand how they function together and maybe someone else can chime in.

    rsTempRecordset.Open strSQL, cnRate, adOpenStatic, adLockReadOnly

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Return Value

    I am assuming that there is a line that follows which check the recordcount of the recordset returned.

    Rs.Recordcount will always return -1 unless you are using a Client side cursor as it will not know how many records there are. -1 indicates that there is an unknown number of records could be 0 could be 500 or more

    if you had used
    Code:
    cnn1.CursorLocation=adUseClient
    when you open your connection then your recordcount would reflect the number of records returned

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: Return Value

    Interesting.....this line works fine with an empty table in MS ACCESS.
    And when I look at rscompany.recordcount. it is ZERO.

    So, you are either not using MS ACCESS or you are getting the -1 from some other check than recordCount (or as DM points out, not client side).

  6. #6
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Return Value

    There are also a number of posts on this forum why you cannot trust that number (RecordCount). I always have used it and have not had any issues I'm aware of. There are a number of warning on this site though as I mentioned.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: Return Value

    @Tyson...aye....always best to add a counter and increment as one runs through the recordset.-That will give a TRUE record count

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Return Value

    In my experience using a client side cursor has always returned an accurate recordcount in ADO. DAO requires you to do a movelast before the recordcount can be trusted and a server side cursor makes for faster execution with less network traffic.

    In general you should not use the client side cursor and thus not the recordcount property. Most times people are just checking to see if the count is > 0 anyway for which a simple test of the .EOF flag works just as well and when using a server side cursor makes for better performance.

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