Results 1 to 4 of 4

Thread: ADO.NET Datareader recordcount

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    Question ADO.NET Datareader recordcount

    is there such an animal as a Datareader Recordcount using ADO.NET - the RecordsAffecfted seems to only apply to Updates, Deletes etc - not Selects. Do I have to write a function which reads the datareader and add up the numbers. Is my datareader then at the end of the recordset and I have to close it and start again to actually process the data. The documentation is rather confusing - If someone could help I would greatly appreciate it

    thanks Brian H

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Nope, I've just been looking for this myself, there is a messy way to achieve the same result though...

    VB Code:
    1. Do while objDataReader.Read = true
    2.     intLoopCounter = intLoopCounter + 1
    3. Loop

    It looks like the read method is similar to the EOF method in ADO, adding this to a loop and incrementing a counter would give you the count.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The datareader doesn't read all the records at once, only when the Read method is called that is why there is no count. You could execute a seperate query or included it in the current one to grab the count(*) of affected rows. Or if you use a dataset you can get the count from the rows.count property.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    maybe you8 are right there is no such animal, funnily enough I started off using the fill dataset and of course coded something like

    Dim Ds1 As New DataSet()
    Dim DbNam As String
    Dim SqlStr As String
    Dim NoRows As Integer
    Dim dg1 As DataGridColumnStyle
    Dim Da1 As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
    DbNam = DbCn1.DbName
    Dim Cn1 As New OleDb.OleDbConnection(DbNam)
    SqlStr = "Select Property,Adr1,Adr2,Adr3 from Properties where Adr1 like '%" & Street & "%'"
    Dim Cmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(SqlStr, Cn1)
    Da1.SelectCommand = Cmd1
    Ds1.Clear()
    NoRows = Da1.Fill(Ds1, "Properties")
    If NoRows = 0 Then
    Me.Cursor = Cursors.Default
    Return "Empty"

    works for me!

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