简体   繁体   English

ASP经典:新表的记录集recordcount -1但旧表可以吗?

[英]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. 我正在使用Classic ASP访问我们的Web服务器上的Access数据库。 The application checks for sensor updates to the web/table, ie printing the last 5 records. 该应用程序检查对Web /表的传感器更新,即打印最后5条记录。 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. 我最近在数据库中添加了一个新表,当我修改代码以从新表中检索记录时,我得到了recordcount = -1,并且只输出最后一条记录。 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? 我已经阅读了有关Recordset游标的信息,但不确定我是否知道如何将其应用于代码,以及为什么该代码不适用于此新表? 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. Id是一个自动编号整数。 At this point the recordcount property is "-1". 此时,recordcount属性为“ -1”。 When I run that Select query directly from the Access Program interface it returns the right number. 当我直接从Access Program界面运行该Select查询时,它将返回正确的数字。

Thanks for any help and insight into why this issue is happening with this table...RDK 感谢您提供任何帮助并深入了解此表为何发生此问题... RDK

The recordcount returns -1 if the recordset isn't fully loaded. 如果记录集未完全加载,则recordcount返回-1。

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. 如果要可靠地使用.RecordCount.MoveLast首先使用.MoveLast来完全加载记录集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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