动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Asp → 阅读文章

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

作者:郁郁小蝎 来源:中国站长学院 
阅读 2346 人次 , 2006-2-15 14:18:00 

二、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
%>


 

  
 本文Tags数据库  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:在ASP中用集合成批操作数据库(一)
· 下一篇:ASP访问SQL Server内置对象
· JScript 方法 - isNaN 方法
· 利用MSCHART画图的一段代码
· 作一个可以直接和浏览器进行交互的组件
· ASP 3.0高级编程(三)
· 在WAP网站上建立反馈表单


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077