明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

在ASP中用集合成批設(shè)置數(shù)據(jù)庫(二)

[摘要]二、HTML的集合屬性的應(yīng)用  下面我們結(jié)合一個(gè)實(shí)際的例子,討論一下如何在ASP頁面中利用HTML的集合屬性來成批操作數(shù)據(jù)庫,F(xiàn)在我們有一個(gè)記錄客戶電子信箱的ACCESS數(shù)據(jù)庫EMail,其中有一個(gè)...

二、HTML的集合屬性的應(yīng)用
  下面我們結(jié)合一個(gè)實(shí)際的例子,討論一下如何在ASP頁面中利用HTML的集合屬性來成批操作數(shù)據(jù)庫,F(xiàn)在我們有一個(gè)記錄客戶電子信箱的ACCESS數(shù)據(jù)庫EMail,其中有一個(gè)數(shù)據(jù)表EmailList,包含CustomerId、CustomerName、CustomerEmail三個(gè)字段,分別表示客戶編號(hào)、客戶名稱、客戶電子信箱。在ASP頁面SelectId.ASP中,我們采用CheckBox列出所有客戶的客戶名稱(各個(gè)CheckBox的值為對應(yīng)的客戶編號(hào)),讓用戶選擇給哪些客戶發(fā)送電子郵件。當(dāng)用戶選擇了客戶并提交數(shù)據(jù)后,SendMail.ASP將檢索到這些客戶的電子信箱,并給這些客戶發(fā)送電子郵件。具體的信息請參見下面ASP程序代碼和注釋信息。

 

<!-- SelectId.ASP:列出所有客戶的客戶名稱 -->
<html><head><title>所有客戶的客戶名稱</title></head><body>
<p align=center><font style="font-family:宋體;font-size:9pt">
請選擇要給哪些客戶發(fā)送“新年問候”的電子郵件
<form method="POST" action="SendMail.asp">
<%'建立與ACCESS數(shù)據(jù)庫的連接
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.open "Driver={Microsoft Access Driver (*.mdb)};"&_
"DBQ=C:\inetpub\wwwroot\test\Email.mdb"
'獲取所有客戶的客戶編號(hào)、客戶名稱
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="給客戶發(fā)送電子郵件" name="B1"
style="font-family:宋體;font-size:9pt">
</form></body></html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<!-- SendMail.ASP:給所選擇客戶發(fā)電子郵件 -->
<html><head><title>給所選擇客戶發(fā)電子郵件</title></head><body>
<p align=center><font style="font-family:宋體;font-size:9pt">
正在給下面客戶發(fā)送電子郵件
<%'建立與ACCESS數(shù)據(jù)庫的連接
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
'給一個(gè)客戶發(fā)電子郵件
Set myMail = CreateObject("CDONTS.NewMail")
myMail.From = "sales@test.com"
myMail.value("Reply-To") = "sales@test.com"
myMail.To = rsCustomers("CustomerEmail")
myMail.Subject = "來自王發(fā)軍的新年問候"
myMail.BodyFormat = 1
myMail.MailFormat = 1
myMail.Body = "王發(fā)軍向"&rsCustomers("CustomerName")&"問好!"
myMail.Send
Set myMail = Nothing
%>
<br>給<a href="mailto:<%=rsCustomers("CustomerEmail")%>"><%=rsCustomers("CustomerName")%></a>
發(fā)送電子郵件成功!
<%
rsCustomers.MoveNext
wend
rsCustomers.close
set rsCustomers = nothing
dbConnection.close
set dbConnection = nothing
%>
<br>在所選擇的客戶發(fā)送電子郵件完畢!
</body></html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

列出你的所有Session變量

<%@ Language=VBScript %>
<% Option Explicit %>
<%
Response.Write "在你的程序中一共使用了 " & Session.Contents.Count & _
" 個(gè)Session變量<P>"
Dim strName, iLoop
For Each strName in Session.Contents
'判斷一個(gè)Session變量是否為數(shù)組
If IsArray(Session(strName)) then
'如果是數(shù)組,那么羅列出所有的數(shù)組元素內(nèi)容
For iLoop = LBound(Session(strName)) to UBound(Session(strName))
Response.Write strName & "(" & iLoop & ") - " & _
Session(strName)(iLoop) & "<BR>"
Next
Else
'如果不是數(shù)組,那么直接顯示
Response.Write strName & " - " & Session.Contents(strName) & "<BR>"
End If
Next
%>