论坛登陆 用户: 密码:
联系我们
设为首页
加入收藏
业界新闻 网络编程 程序开发 网页图象 聊天通讯 软件应用 网络安全 硬件学堂 教育频道 站长club
  ·推荐新闻
 
·美前任官员认为amd告倒英特
·搜索引擎关键字排行简介
·网站优化教程(一)
·msn近期遭受木马病毒骚扰 用
·用qq管理你的系统^_^ 
·测评中心金山毒霸联合发布7
·qq群聊实名 普通用户不受影
·雅虎思科联手推数字邮件签名
·这18条背下来没人敢和你忽悠
·自己动手,拯救丢失的硬盘数
  ·资料搜索
 
  ·相关文章
·绑定txt文件到datagrid
·在用户离开页面时提示信息
·asp + oracle 分页方法(不用存
·asp + sqlserver 分页方法(不
·asp无组件上传进度条解决方案
·验证身份证号是否正确的代码
·类似于iis浏览的功能
·检查有日文片假名的新闻
·asp关键字函数运算附
·asp中也能解压缩rar文件
  ·热门新闻
首页>>网络编程>>asp专区>>文章正文

在ASP中用集合成批操作数据库(二)


 日期:2005-7-18 8:26:20     来源:易特网络技术   编辑:黑鹰  点击:

二、HTML的集合属性的应用
  下面我们结合一个实际的例子,讨论一下如何在ASP页面中利用HTML的集合属性来成批操作数据库。现在我们有一个记录客户电子信箱的ACCESS数据库email,其中有一个数据表emaillist,包含customerid、customername、customeremail三个字段,分别表示客户编号、客户名称、客户电子信箱。在ASP页面selectid.asp中,我们采用checkbox列出所有客户的客户名称(各个checkbox的值为对应的客户编号),让用户选择给哪些客户发送电子邮件。当用户选择了客户并提交数据后,sendmail.asp将检索到这些客户的电子信箱,并给这些客户发送电子邮件。具体的信息请参见下面ASP程序代码和注释信息。

 

<!-- selectid.asp:列出所有客户的客户名称 -->
<html><head><title>所有客户的客户名称</title></head><body>
<p align=center><font style="font-family:宋体;font-size:9pt">
请选择要给哪些客户发送“新年问候”的电子邮件
<form method="post" action="sendmail.asp">
<%'建立与access数据库的连接
set dbconnection = server.createobject("adodb.connection")
dbconnection.open "driver={microsoft access driver (*.mdb)};"&_
"dbq=c:\inetpub\wwwroot\test\email.mdb"
'获取所有客户的客户编号、客户名称
set rscustomers = server.createobject("adodb.recordset")
rscustomers.open "select customerid,customername,customeremail from emaillist",_
dbconnection,1,3,1
'显示所有客户的客户名称
while not rscustomers.eof
%>
<br><input type="checkbox" name="customerid" value="<%=rscustomers("customerid")%>">
<a href="mailto:<%=rscustomers("customeremail")%>">
<%=rscustomers("customername")%></a>
<%rscustomers.movenext
wend
rscustomers.close
set rscustomers = nothing
dbconnection.close
set dbconnection = nothing
%>
<br><input type="submit" value="给客户发送电子邮件" name="b1"
style="font-family:宋体;font-size:9pt">
</form></body></html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<!-- sendmail.asp:给所选择客户发电子邮件 -->
<html><head><title>给所选择客户发电子邮件</title></head><body>
<p align=center><font style="font-family:宋体;font-size:9pt">
正在给下面客户发送电子邮件
<%'建立与access数据库的连接
set dbconnection = server.createobject("adodb.connection")
dbconnection.open "driver={microsoft access driver (*.mdb)};"&_
"dbq=c:\inetpub\wwwroot\test\email.mdb"
'获取所选择客户的电子信箱
set rscustomers = server.createobject("adodb.recordset")
rscustomers.open "select customername,customeremail from emaillist where customerid in ("&_
request("customerid")&")",dbconnection,1,3,1
while not rscustomers.eof
'给一个客户发电子邮件
set mymail = createobject("cdonts.newmail")
mymail.from = "sales@test.com"
mymail.value("reply-to") = "sales@test.com"
mymail.to = rscustomers("customeremail")
mymail.subject = "来自王发军的新年问候"
mymail.bodyformat = 1
mymail.mailformat = 1
mymail.body = "王发军向"&rscustomers("customername")&"问好!"
mymail.send
set mymail = nothing
%>
<br>给<a href="mailto:<%=rscustomers("customeremail")%>"><%=rscustomers("customername")%></a>
发送电子邮件成功!
<%
rscustomers.movenext
wend
rscustomers.close
set rscustomers = nothing
dbconnection.close
set dbconnection = nothing
%>
<br>在所选择的客户发送电子邮件完毕!
</body></html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

列出你的所有session变量

<%@ language=vbscript %>
<% option explicit %>
<%
response.write "在你的程序中一共使用了 " & session.contents.count & _
" 个session变量<p>"
dim strname, iloop
for each strname in session.contents
'判断一个session变量是否为数组
if isarray(session(strname)) then
'如果是数组,那么罗列出所有的数组元素内容
for iloop = lbound(session(strname)) to ubound(session(strname))
response.write strname & "(" & iloop & ") - " & _
session(strname)(iloop) & "<br>"
next
else
'如果不是数组,那么直接显示
response.write strname & " - " & session.contents(strname) & "<br>"
end if
next
%>


 


上一篇:优化web数据库页面
下一篇:在ASP中用集合成批操作数据库(一)
[发送给好友] [打印本页] [关闭窗口] [返回顶部转载请注明来源:http://www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 黑鹰 投稿作者: 易特网络
信息来源: 易特网络技术 录入时间: 2005-7-18 8:26:20
浏览次数: 投稿信箱: shtghy@163.com
设置首页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
copyrights ©2004-2005 iyit.net all rights reserved. 网站合作、广告联系qq:147007642、466949678
易特网络技术 点击这里给我发消息