当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在ASP中用集合成批操作数据库(二)

ASP
用asp执行DTC
利用ADODB.Stream使用浏览器下载服务器文件
应用数据库的唯一性约束并在asp中捕捉数据库的错误
用ASP编程控制在IIS建立Web站点
asp实现k线图(在线)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(7)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(6)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(5)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(4)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(3)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(2)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(1)
用文本+ASP打造新闻发布系统。几点补充
用文本+ASP打造新闻发布系统(五)新闻修改
用文本+ASP打造新闻发布系统(四)新闻删除
用文本+ASP打造新闻发布系统(三)新闻列表显示
用文本+ASP打造新闻发布系统(二)新闻添加
ASP作的剪包锤游戏
ASP注册表项目修改
构建稳定的服务器端组件的七个步骤

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 18 ::
收藏到网摘: n/a

二、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 = "[email protected]"
myMail.value("Reply-To") = "[email protected]"
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变