简体   繁体   中英

ASP Classic: recordset recordcount -1 for new table but older ones ok?

I'm working with Classic ASP accessing an Access database on our webserver. The application checks for sensor updates to the web/table, ie printing the last 5 records. This code has worked for several tables historically. I recently added a new table to the database and when I modify the code to retrieve records from the new table I get a recordcount = -1 and it only outputs the last record. I have read about the Recordset Cursor but not sure I understand how to apply that to my code and also why the code does not work for this new table? Here is the basic code to retrieve the records for printing:

WebName = "OurWeb"
MySite = "filedsn=" & Server.MapPath("/" & WebName & "/files/reffiles/accessdsn.dsn") & ";DBQ=" & Server.MapPath("/" & WebName & "/files/reffiles/loger.mdb") & ";DefaultDir=" _
& Server.MapPath("/" & WebName & "/") & ";"

set MyDatabase = server.createobject("ADODB.Connection")
if err.number <> 0 then response.write("<p>ODBC Error</p>")
Mydatabase.open MySite 

set LastMyDate = MyDatabase.Execute("SELECT Format(Max([Date_Time]),'mm/dd/yy hh:mm:ss') AS Expr1 FROM Charger2;")

set LastMYDate = MyDatabase.Execute("SELECT Charger2.id FROM Charger2 WHERE Charger2.date_Time = #" & lastMGdate.fields(0).value & "#;")

MyIDLast = LastMyDate.fields(0).value -5
set LastMyRecord = MyDatabase.Execute("SELECT Charger2.id,  Charger2.date_time,  Charger2.INV_vdc,  Charger2.INV_adc FROM Charger2 WHERE (((Charger2.id) > (" & MyIDLast & ")));")

Id is an Autonumber Integer. At this point the recordcount property is "-1". When I run that Select query directly from the Access Program interface it returns the right number.

Thanks for any help and insight into why this issue is happening with this table...RDK

The recordcount returns -1 if the recordset isn't fully loaded.

When using an aggregate query that returns a single record, it's often fully loaded. But if you filter a nonindexed column, it might not be.

If you want to reliably use .RecordCount , use .MoveLast first to fully load the recordset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM