ADO初學(xué)者教程:ADO 顯示_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:ADO初學(xué)者教程:ADO 添加記錄我們可以使用SQL的INSERT INTO命令向數(shù)據(jù)庫中的表添加記錄。 向數(shù)據(jù)庫中的表添加記錄 我們希望向Northwind數(shù)據(jù)庫中的Customers表添加一條新的記錄。我們首先要?jiǎng)?chuàng)建一個(gè)表單,這個(gè)表單包含了我們希望選定數(shù)據(jù)的字段: htmlbodyform method=post action=dem
顯示來自記錄集中的數(shù)據(jù)的最常用的方法,就是把數(shù)據(jù)顯示在HTML表格中。
顯示字段名稱和字段值
我們有一個(gè)名為"Northwind"的數(shù)據(jù)庫,并且我們希望顯示出"Customers"表中的數(shù)據(jù)(記得以.asp為擴(kuò)展名來保存這個(gè)文件):
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM Customers", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "<br />")
next
Response.Write("<br />")
rs.MoveNext
loop
rs.close
conn.close
%>
</body>
</html>
在一個(gè)HTML表格中顯示字段名稱和字段的值
我們也可以通過下面的代碼把表"Customers"中的數(shù)據(jù)顯示在一個(gè)HTML表格中:
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
%>
<table border="1" width="100%">
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
</body>
</html>
向HTML表格添加標(biāo)題
我們希望為這個(gè)HTML表格添加標(biāo)題,這樣它就更易讀了:
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
</body>
</html>
分享:ADO初學(xué)者教程:ADO 更新記錄我們可使用SQL的UPDATE來更新數(shù)據(jù)庫表中的某條記錄。 更新數(shù)據(jù)庫表中的記錄 我們希望更新Northwind數(shù)據(jù)中Customers表的某條記錄。首先我們需要?jiǎng)?chuàng)建一個(gè)表格,來列出Customers中的所有記錄。 htmlbody%set conn=Server.CreateObject(ADODB.Connection)conn.
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-ADO初學(xué)者教程:ADO 顯示
。