<%@ 导入命名空间="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>