Having trouble with RS.RecordCount

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Having trouble with RS.RecordCount

  1. #1
    Sam Pfanstiel Guest

    Default Having trouble with RS.RecordCount

    [1 in a series]<BR><BR>Having helped develop several dozen web based applications in ASP for ODBC access 97 databases, I am trying to upsize my code to SQL server 7.0.<BR><BR>One particular item is giving me some trouble:<BR><BR>The RS.RecordCount propery is always -1, no matter the size of my recordset. I&#039m using If not RS.BOF and not RS.EOF to get around this for beginning record scans, but I really would like to get this variable working for other issues. Any help?

  2. #2
    Join Date
    Dec 1969
    Posts
    760

    Default RE: Having trouble with RS.RecordCount

    Your .RecordCount is always -1 because it refers to records accessed or read since creating the recordset object. To get around the problem, try "recordset.MoveLast" followed by "recordset.MoveFirst". Remember that you must use a dynamic cursor and not the default forward only. This should solve your .RecordCount problem. Keep in mind however, that the method outlined above is not efficient and if your recordsets contain more that 10 to 50 records, I wouldn&#039t recommend it using it. Instead, try running a "SELECT COUNT(*) FROM table_name WHERE yourcriteria". This is so much faster. Hope this helps.

  3. #3
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Having trouble with RS.RecordCount

    here are a couple great articles on 4Guys explaining how to overcome this!<BR><BR>Choosing the Right Cursor for the Job<BR>http://4guysfromrolla.com/webtech/112998-1.shtml<BR><BR>Cursor Support for Various ADO Commands<BR>http://www.activeserverpages.com/learn/adocursortypes.asp<BR><BR>How NOT to count the Records in a Recordset<BR>http://4guysfromrolla.com/webtech/120898-1.shtml<BR><BR><BR>Happy Programming!

  4. #4
    Sam Pfanstiel Guest

    Default RE: Having trouble with RS.RecordCount

    Thanks for the articles. I guess it&#039s pretty common knowledge, but I mistakenly assumed that ADO was pretty much a common gateway interface whether I was dealing with ODBC or SQL. (Ok, go easy on me... and stop laughing already!)<BR><BR>Thanks again.


  5. #5
    Join Date
    Dec 1969
    Posts
    135

    Default RE: Having trouble with RS.RecordCount

    Use Cursor type=3 and Lock type=1.<BR>This is the only combination for rs.recordcount which will work as far as I know.

  6. #6
    Join Date
    Dec 1969
    Posts
    99

    Default RE: Having trouble with RS.RecordCount

    use-&#062; rs1.Open select * from temp ,conection,1,3<BR>Will solve your problem

  7. #7
    Join Date
    Dec 1969
    Posts
    96,118

    Default PLEASE stop answering 6-month old messages!

    Look at the dates! These threads are long gone. The answers have been given long ago. <BR><BR>You are NOT helping by bringing back these old threads. PLEASE stop it.<BR><BR>

  8. #8
    Join Date
    Dec 1969
    Posts
    12

    Default RE: Having trouble with RS.RecordCount

    thanx that work for me

  9. #9
    Rod Petrovic Guest

    Default RE: PLEASE stop answering 6-month old messages!

    I was trying to find an answer to this question and while those "six-month old answers" only baffled me, this fresh message gave me a simple solution to my problem. Therefore, I don&#039;t agree with you. There are never too many answers...

  10. #10
    ASPwizard Webmaster Guest

    Default RE: Having trouble with RS.RecordCount

    All this messages are wrong, try to use both examples and its wrond it should be.<BR><BR>rsStats.Open strSQL,Conn,1,1

Posting Permissions

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