How to read entries in ASP classic?

I am not very good at ASP classic programming. I just need a little code to work on my web page. How to count the record of the returned request?

<%
Set rsscroll = Server.CreateObject("ADODB.Recordset")
Dim strSQLscroll, rsscroll
strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc;"
rsscroll.open strSQLscroll,oConn
%>

thanks,

+3
source share
9 answers

It is possible (but not recommended) to use the RecordCount property on the Recordset object as follows:

iTotalRecords = rsscroll.RecordCount

If your table is really large, this can take a long time. Instead, I ran a separate SQL query to get the totals.

SQL = "SELECT COUNT(*) AS TotalRecords FROM tblItems WHERE expiration_date > getdate() "
set rsRecordCount = conn.Execute(SQL)
if not rsRecordCount.Eof then
  iTotalRecords = rsRecordCount.Fields("TotalRecords")
else
  iTotalRecords = 0
end if
rsRecordCount.Close
set rsRecordCount = nothing
+7
source

rsscroll. RecordCount

+6
source

SQL COUNT. , , .

<%
    Set rsscroll = Server.CreateObject("ADODB.Recordset")
    Dim strSQLscroll, rsscroll, intRow
    strSQLscroll = "SELECT COUNT(*) AS Total FROM tblItems WHERE expiration_date > getdate();"
    rsscroll.open strSQLscroll, oConn
    response.write rsscroll("Total")
    rsscroll.close: set rsscroll = nothing 
    oConn.close: set oConn = nothing 
%>

, "Total". (, , .)

RecordSet , " " . , . ( RecordSet.RecordCount -1, .)

RecordSet.Open " " "Keyset" ( 1), RecordCount . ( " " " " , .)

RecordsetObject.Open "TableName|SQLStatement", ConnectionObject [,Cursor Type] [,Lock Type] [,Command Type] 

RecordSet. , RecordCount.

<%
    Set rsscroll = Server.CreateObject("ADODB.Recordset")
    Dim strSQLscroll, rsscroll, intRow
    strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc;"
    rsscroll.open strSQLscroll, oConn, 1
    intRow = rsscroll.RecordCount
    ' ... do something with intRow
    rsscroll.close: set rsscroll = nothing 
    oConn.close: set oConn = nothing 
%>

- , RecordSet.GetRows() .

<% 
    Dim rsscroll, intRow, rsArray
    Set oConn = CreateObject("ADODB.Connection") 
    oConn.open "<connection string>" 
    strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc" 
    Set rsscroll = conn.execute(strSQLscroll) 
    if not rsscroll.eof then 
        rsArray = rsscroll.GetRows() 
        intRow = UBound(rsArray, 2) + 1 
        response.write "rows returned: " & intRow
        ' ... do any other operations here ... 
    end if 
    rsscroll.close: set rsscroll = nothing 
    oConn.close: set oConn = nothing 
%>
+2

SQL :

strSQLscroll = "SELECT count(*) as Total FROM tblItems where expiration_date > getdate();"

response.write rsscroll("Total")

+1

, "select count (*) ", , , - , , "TotalUnits = TotalUnits + rs (" Units "). " . , , , .

+1

Get in memory storage of returned data in arrays. This is surprisingly faster to repeat than using an open set of records. In addition, specify the fields for selection in this case, since you need to explicitly refer to the index of the array.

<%
Set rsscroll = Server.CreateObject("ADODB.Recordset")
Dim strSQLscroll, rsscroll
Dim arrCommon

'Open recordset, copy data to array
strSQLscroll = "SELECT field1, field2, field3 FROM tblItems where expiration_date > getdate() order by expiration_date desc;"
rsscroll.open strSQLscroll,oConn
    arrCommon = rsscroll.getRows()
rsscroll.close

'Get the total records in this array
response.write ubound(arrCommon, 2);

'Loop...
for i = 0 to ubound(arrCommon, 2)

    ' This prints field 3
    response.write arrCommon(2, i)

next
%>
+1
source

<% 'TableID = your table identifier ...

Set rsscroll = Server.CreateObject("ADODB.Recordset") Dim strSQLscroll, rsscroll strSQLscroll = "SELECT *,(SELECT TableID FROM tblItems where expiration_date > getdate()) As Count FROM tblItems where expiration_date > getdate() order by expiration_date desc;" 
rsscroll.open strSQLscroll,oConn
Count = rsscroll("Count") 

%>

0
source

You can try this

    Dim count
    count = 0
    if strSQLscroll.eof <> true or strSQLscroll.bof <> true then
       while not strSQLscroll.eof
          count = count+1
          strSQLscroll.movenext
       wend
    end if
    response.write(count)
0
source

If you are using MySQL, try the following:

Dim strSQLscroll, rsscroll, countrs

Set rsscroll = Server.CreateObject("ADODB.Recordset")
rsscroll.CursorLocation = 3
rsscroll.open "SELECT * FROM tblItems where expiration_date > getdate()
order by expiration_date desc;",oConn

countrs = rsscroll.recordcount
0
source

Source: https://habr.com/ru/post/1711473/


All Articles