Asp classic 3.0循环和movenext

时间:2015-06-03 09:04:05

标签: loops asp-classic

我对此Asp Classic 3.0代码有疑问。

我需要在数据库表中找到的sql查询时发送电子邮件消息:

using

我尝试过这个Asp代码:

SQL = " SELECT * FROM doTable Where div = 1; "

问题在于代码的这一部分:

   SQL = " SELECT * FROM doTable Where div = 1; "

   Set Rec = createObject("ADODB.Recordset")
   Rec.open SQL, cn

   If not Rec.eof then

   msg = msg & VBcrlf & "<br />Records founds!<br />"

   Do while not Rec.eof 

   msg = msg & VBcrlf & "ID record: " & Rec("Id") & ""         

   msg = ""

   Rec.moveNext()      
   Loop       

   Else

   msg = msg & VBcrlf & "<br />No records!<br />"

   End If

   Rec.close()
   set Rec = nothing    

   cn.close()
   set cn = nothing 

如果我找到了记录并且代码中存在 msg =“”,则msg的输出为空;如果代码中不存在 msg =“”,则输出为:

msg = ""

为什么我不能得到这个输出?

Records founds!
ID record: 32
Records founds!
ID record: 61
Records founds!
ID record: 77
你能帮帮我吗? 提前谢谢 -

修改

Records founds!
ID record: 32
ID record: 61
ID record: 77

3 个答案:

答案 0 :(得分:1)

我认为您正在寻找的是Rec.recordcount,可以像这样使用:

Set Rec = server.createObject("ADODB.Recordset")
Rec.open SQL, cn
somevar=Rec.recordcount

然后somevar可用于显示如下:

There are <%=somevar%> records.

答案 1 :(得分:0)

我认为代码是正确的。输出变量 msg

的rige在哪里?
Records founds!
ID record: 32
Records founds!
ID record: 61
Records founds!
ID record: 77

也许这是3个查询的输出?

答案 2 :(得分:0)

msg = msg & VBcrlf & "ID record: " & Rec("Id") & ""         

msg = ""

此代码没有意义,msg = ""将msg的值更改为空字符串,并使前一行无意义。在开始循环记录集之前让msg = ""更有意义。

试试这个

SQL = " SELECT * FROM doTable Where div = 1; "

msg = ""

msg = msg & VBcrlf & "<br />Records founds!<br />"


   Set Rec = server.createObject("ADODB.Recordset")
   Rec.open SQL, cn

   If Rec.eof and rec.bof then

   msg = "<br />No records!<br />"

   else

   Do while not Rec.eof 

   msg = msg & VBcrlf & "ID record: " & Rec("Id") & ""         

   Rec.moveNext     
   Loop       

   End If

   Rec.close
   set Rec = nothing    

   cn.close
   set cn = nothing