locked
counting records in an ado.net recordset RRS feed

  • Question

  • Hi

    I have a recordset rst, that returns the data i require ok.  However i wish to transfer this data into an array, and also count the amount of records, as a counter, i.e. 23/312 records.

    How is this possible?  I have tried the way i have used in the past, not .net, of rst.movelast etc, but this doesnt seem to work.

    thanks
    Friday, August 14, 2009 9:21 AM

Answers

  • An ADO Recordset has a GetRows property that will allow you to copy all of the data into an Array.

    You may also want to consider using an ADO.NET DataTable instead of a Recordset and Array (as Deborah mentioned).


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, August 14, 2009 7:41 PM

All replies

  • HI

            Dim Totalrst As Integer = 213
            Dim Counter As Integer = 0

            ' then every record your program produces, the counter counts the number of produced number

            ' If you delete a record then you deduce the number of the counter

            For i As Integer = 1 To Totalrst

                Counter = Counter + 1 ' Or  Counter = Counter - 1 if you want to delete

                RichTextBox1.AppendText(Counter & "/" & Totalrst)

            Next

    Kind Regards


    K Fendi - UK
    Friday, August 14, 2009 3:16 PM
  • If this is ADO.NET, I assume you mean a DataSet or a DataTable and not a recordset?

    This provides the count of rows in a DataTable:

    Dim count As Integer = dt.Rows.Count
    And the Rows collection already provides the list of rows. What do you require the array for?

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Friday, August 14, 2009 3:19 PM
  • An ADO Recordset has a GetRows property that will allow you to copy all of the data into an Array.

    You may also want to consider using an ADO.NET DataTable instead of a Recordset and Array (as Deborah mentioned).


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, August 14, 2009 7:41 PM