推薦: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", conndo 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.MoveNextlooprs.closeconn.close%></body></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><%looprs.closeconn.close%></table></body></html>
我們希望為這個(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.
新聞熱點(diǎn)
疑難解答
圖片精選