Click to See Complete Forum and Search --> : ADO.NET Datareader recordcount
briancps
Nov 14th, 2002, 01:14 AM
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
alex_read
Nov 14th, 2002, 07:57 AM
Nope, I've just been looking for this myself, there is a messy way to achieve the same result though...
Do while objDataReader.Read = true
intLoopCounter = intLoopCounter + 1
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. :)
Edneeis
Nov 14th, 2002, 10:45 AM
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.
RichardAtherton
Nov 14th, 2002, 03:18 PM
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!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.