Asp 经典 3.0 循环和 movenext
Asp classic 3.0 loop and movenext
我对这个 Asp 经典 3.0 代码有疑问。
当 sql 查询在数据库 table 中找到包含 :
的记录时,我需要发送电子邮件消息
SQL = " SELECT * FROM doTable Where div = 1; "
我试过这个 Asp 代码:
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
你能帮帮我吗?
提前谢谢你-
编辑
With objMessage
.From = RS("Email_from")
.To = RS("Email_to")
.Subject = "Alert div"
.HtmlBody = msg
.Fields("urn:schemas:httpmail:importance").Value = 2
.Fields("urn:schemas:mailheader:X-MSMail-Priority") = 6
.Fields.Update()
on error resume next
.Send
if Err.Number <> 0 then
response.Write "Email send failed # : " & Err.Number & " - " & Err.Description & ".<br />"&vbcrlf
end if
End With
我认为代码是正确的。输出变量msg?
的条件在哪里
Records founds!
ID record: 32
Records founds!
ID record: 61
Records founds!
ID record: 77
也许这是 3 查询的输出?
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
我想你要找的是Rec.recordcount,可以这样使用:
Set Rec = server.createObject("ADODB.Recordset")
Rec.open SQL, cn
somevar=Rec.recordcount
然后somevar可以用来显示这样的:
There are <%=somevar%> records.
我对这个 Asp 经典 3.0 代码有疑问。
当 sql 查询在数据库 table 中找到包含 :
的记录时,我需要发送电子邮件消息SQL = " SELECT * FROM doTable Where div = 1; "
我试过这个 Asp 代码:
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
你能帮帮我吗? 提前谢谢你-
编辑
With objMessage
.From = RS("Email_from")
.To = RS("Email_to")
.Subject = "Alert div"
.HtmlBody = msg
.Fields("urn:schemas:httpmail:importance").Value = 2
.Fields("urn:schemas:mailheader:X-MSMail-Priority") = 6
.Fields.Update()
on error resume next
.Send
if Err.Number <> 0 then
response.Write "Email send failed # : " & Err.Number & " - " & Err.Description & ".<br />"&vbcrlf
end if
End With
我认为代码是正确的。输出变量msg?
的条件在哪里Records founds!
ID record: 32
Records founds!
ID record: 61
Records founds!
ID record: 77
也许这是 3 查询的输出?
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
我想你要找的是Rec.recordcount,可以这样使用:
Set Rec = server.createObject("ADODB.Recordset")
Rec.open SQL, cn
somevar=Rec.recordcount
然后somevar可以用来显示这样的:
There are <%=somevar%> records.