|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
count of records in recordsetHi,
I need to know how many records i get from a sql statement. I use this and it works (amount of records = rec), but is there no better way to to that? Thanks Dominique ... comd = New System.Data.OleDb.OleDbCommand(sql, oConnection) dtreader = comd.ExecuteReader If dtreader.HasRows Then While dtreader.Read() rec = rec + 1 End While End If dtreader.Close() 2 options:
-Do a count (*) query. If you need the data and the count, this would mean you execute the query a second time, essentially. -Use a datatable instead of a datareader. Additionally, this question has been asked hundreds of times. If you do a google search you will find similar responses. Show quote "D." <d.***@rtt.com> wrote in message news:eHp7P4edGHA.4900@TK2MSFTNGP02.phx.gbl... > Hi, > > I need to know how many records i get from a sql statement. > I use this and it works (amount of records = rec), but is there no better > way to to that? > Thanks > Dominique > > ... > comd = New System.Data.OleDb.OleDbCommand(sql, oConnection) > dtreader = comd.ExecuteReader > If dtreader.HasRows Then > While dtreader.Read() > rec = rec + 1 > End While > End If > dtreader.Close() > > Thanks
Show quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:uXcBs8edGHA.3888@TK2MSFTNGP04.phx.gbl... > 2 options: > > -Do a count (*) query. If you need the data and the count, this would mean > you execute the query a second time, essentially. > -Use a datatable instead of a datareader. > > Additionally, this question has been asked hundreds of times. If you do a > google search you will find similar responses. > > "D." <d.***@rtt.com> wrote in message > news:eHp7P4edGHA.4900@TK2MSFTNGP02.phx.gbl... > > Hi, > > > > I need to know how many records i get from a sql statement. > > I use this and it works (amount of records = rec), but is there no better > > way to to that? > > Thanks > > Dominique > > > > ... > > comd = New System.Data.OleDb.OleDbCommand(sql, oConnection) > > dtreader = comd.ExecuteReader > > If dtreader.HasRows Then > > While dtreader.Read() > > rec = rec + 1 > > End While > > End If > > dtreader.Close() > > > > > > |
|||||||||||||||||||||||