Results 1 to 11 of 11

Thread: [RESOLVED] counting records

  1. #1

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Resolved [RESOLVED] counting records

    .pls help me..

    using adodc
    how to count the records entered in the table.

    i've tried this code
    Code:
    Dim rec As ADODB.Recordset
    Text1.Text = rec.RecordCount
    but it always returns -1

    ??? why..
    Last edited by macmatira; May 16th, 2011 at 07:50 AM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: counting records

    There are couple of reasons:

    1. You need to set recordset CursorLocation to client first.
    Code:
    Dim RST As ADODB.Recordset
    
        Set RST = New ADODB.Recordset
        rst.CursorLocation = adUseClient
    2. Not every data provider supports the record count.

  3. #3

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: counting records

    ty i will try.

  4. #4

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: counting records

    thanks....

    i got it...

    pls help me, if i will encounter another problem in my way..

    thank you very much!

  5. #5

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: [RESOLVED] counting records

    before the prob.
    i would like to thanks for your kindness.
    thanks for the answers.

    pls help me for this another prob.

    here is the link

    http://www.vbforums.com/showthread.php?t=650166

  6. #6

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: counting records

    Quote Originally Posted by RhinoBull View Post
    There are couple of reasons:

    1. You need to set recordset CursorLocation to client first.
    Code:
    Dim RST As ADODB.Recordset
    
        Set RST = New ADODB.Recordset
        rst.CursorLocation = adUseClient
    2. Not every data provider supports the record count.
    i got a trouble.

    pls help me again.

    here is the code i've entered.

    Code:
    Private Sub Command1_Click()
    Set rec = New ADODB.Recordset
    rec.CursorLocation = adUseClient
    
    'to see how many records in the table
    Text1.Text = rec.CursorLocation
    
    MSFlexGrid1.TextMatrix(1, 0) = rec.Fields(0)
    
    End Sub
    then the attachment is the screen shot of the error.
    the error is in the rec.fields (0) and said that:
    Item cannot be found in the collection corresponding to the requested name or ordinal.
    Attached Images Attached Images  
    Last edited by macmatira; May 17th, 2011 at 01:15 PM. Reason: additional information. (ellaboration)

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [RESOLVED] counting records

    That is because there is no column name CursorLocation in the record set. That is an attribute of a recordset. What you want is rec.RecordCount
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: [RESOLVED] counting records

    my first problem is how to count the records.. but it is resolved using the codes given by RhinoBull...

    then now, i have the problem of viewing the record using the msflexgrid
    ...

    if i'm not mistaken, the code.
    Code:
    Set rec = New ADODB.Recordset
    rec.CursorLocation = adUseClient
    is use to move the cursor to the last row of the table.

    using other command button. (command2)
    i can view it, and there is no error.

    but i want is to know how many records and the same time viewing the record in the msflexgrid.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] counting records

    When you use a client side cursor, the recordcount property will return an accurate number.

    -1 is returned for a recordcount only when you are using a server side cursor.

  10. #10

    Thread Starter
    Junior Member macmatira's Avatar
    Join Date
    Mar 2010
    Posts
    21

    Re: [RESOLVED] counting records

    thanks sir, i got it. (about the client and server side cursor)

    but my problem now,,,

    the second problem i've mentioned above. (with attachment)

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: counting records

    Quote Originally Posted by macmatira View Post
    the error is in the rec.fields (0) and said that:
    Item cannot be found in the collection corresponding to the requested name or ordinal.
    You are not selecting any records - if you do then at least it's not presented here.
    There must some kind of "Select * From..." sql staement executed.
    If you are beginner to database programming I would recommend checking out Database FAQ section for lots tutorials, tips and sample code.

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