SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 9 of 9

Thread: ADODB.RecordSet

  1. #1
    Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    381
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    ADODB.RecordSet

    Set objDB = CreateObject("ADODB.Connection")
    Set objRS = CreateObject("ADODB.RecordSet")
    ' configure the connection
    objDB.Provider="Microsoft.Jet.OLEDB.4.0"
    objDB.Open "c:\MyTestDatabase.mdb"
    ' count the number of records in the employee table
    objRS.Open "Select * from Customers" , objDB


    msgbox objRS.RecordCount ' it is printing -1 !

    'If i use for loop , it prints all values in table properly!

    For i=1 to 5
    Msgbox objRS.Fields("Customer_Name").Value
    objRS.MoveNext
    Next

    can you tell me why it shows "-1" for RecordCount and When i tried MaxRecords property, it prints 0!
    <font color="blue">[i]If there is no struggle, there is no progress!

  2. #2
    Member
    Join Date
    Oct 2010
    Posts
    218
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    objRS.fields.count Will give you the count of the Records.

  3. #3
    Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    381
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    [ QUOTE ]
    objRS.fields.count Will give you the count of the Records.

    [/ QUOTE ]
    it gives count as 8 which is number of COLUMNS in the table!
    I want count of records
    <font color="blue">[i]If there is no struggle, there is no progress!

  4. #4
    Super Member QAGanesh's Avatar
    Join Date
    Sep 2010
    Posts
    1,898
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    -1 gets displayed if your recordset cursor type is forward only and not static.

    Also may b this property is not supported for this kind of recordset, so it returns -1.

    Try objRS.Properties.Count and check the value
    Thanks,
    Ganesh Iyer
    Winds of Change

  5. #5
    Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    381
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    Properties.Count prints 88,there are 10 records only.
    <font color="blue">[i]If there is no struggle, there is no progress!

  6. #6
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    You might also want to try:

    objRS.MoveFirst
    msgbox objRS.RecordCount

    Mark Smith.

  7. #7
    Junior Member
    Join Date
    Mar 2009
    Posts
    16
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    Try this:

    <font color="blue"> objRS.Open "Select * from Customers" , objDB, 3,2 </font>

    msgbox objRS.RecordCount

    this will solve your issue.

  8. #8
    Super Member QAGanesh's Avatar
    Join Date
    Sep 2010
    Posts
    1,898
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    True scottli,

    The recordcount works only when the recordset is open.
    Thanks,
    Ganesh Iyer
    Winds of Change

  9. #9
    Member
    Join Date
    Jul 2011
    Location
    India
    Posts
    381
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ADODB.RecordSet

    [ QUOTE ]
    Try this:

    <font color="blue"> objRS.Open "Select * from Customers" , objDB, 3,2 </font>

    msgbox objRS.RecordCount

    this will solve your issue.

    [/ QUOTE ]

    It's working perfect now.
    Just went through
    http://www.w3schools.com/ado/met_rs_open.asp
    and wondering which enum constants do these 3,2 represent as all of them are optional!
    By the way it also works fine for
    objRS.Open "Select * from oRDERS" , objDB,3 ' no need of 2
    <font color="blue">[i]If there is no struggle, there is no progress!

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:47 PM.

Copyright BetaSoft Inc.