<%@ 導入命名空間="System.Data" %>
<%@ 導入 NameSpace="System.Data.OleDb" %>
<script laguage="VB" runat="伺服器">
將 myConnection 調暗為 OleDbConnection
將 myCommand 調暗為 OleDbCommand
sub page_load(sender as Object,e as EventArgs)
'1.連接資料庫
將資料庫名稱暗淡為字串
dbname=server.mappath("authors.mdb")
myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source="&dbname )
myConnection.Open()
la1.text="連線已開啟!"
'2.新增記錄
myCommand = New OleDbCommand( "插入 INTO 作者(作者,國家) 值('Simson','usa')", myConnection )
myCommand.ExecuteNonQuery()
la2.text="已插入新記錄!"
'3更新資料(存取)
myCommand = New OleDbCommand( "UPDATE Authors SET Authors='Bennett' WHERE Authors = 'Simson'", myConnection )
myCommand.ExecuteNonQuery()
la3.text="記錄已更新!"
'4刪除資料(存取)
myCommand = New OleDbCommand( "從作者中刪除,其中作者 = 'David'", myConnection )
myCommand.ExecuteNonQuery()
la4.text="記錄已刪除!"
'5 使用DateGrid顯示數據
myCommand = New OleDbCommand("從作者中選擇 *", myConnection )
MyDataGrid.DataSource=myCommand.Executereader()
MyDataGrid.DataBind()
結束子
</腳本>
<html>
<正文>
<asp:label id="la1" runat="伺服器" /><br>
<asp:label id="la2" runat="伺服器" /><br>
<asp:label id="la3" runat="伺服器" /><br>
<asp:label id="la4" runat="伺服器" /><br>
<ASP:DataGrid id =“MyDataGrid”runat =“伺服器”
邊框顏色=“黑色”
邊框寬度=“1”
網格線=“兩者”
單元格填充=“3”
單元格間距=“0”
字型名稱=“Verdana”
字體大小=“10pt”
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
>
</asp:DataGrid>
</body>
</html>