<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<script laguage="VB" runat="서버">
myConnection을 OleDbConnection으로 흐리게 설정
myCommand를 OleDbCommand로 흐리게 설정
하위 페이지_로드(발신자: Object,e: EventArgs)
'1.连接数据库
문자열로 희미한 DB 이름
dbname=server.mappath("authors.mdb")
myConnection = 새 OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA 소스="&dbname )
myConnection.Open()
la1.text="연결이 열렸습니다!"
'2.添加记录
myCommand = New OleDbCommand( "Insert INTO Authors(Authors,country) Values('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( "DELETE FROM Authors WHERE Authors = 'David'", myConnection )
myCommand.ExecuteNonQuery()
la4.text="기록이 삭제되었습니다!"
'5 使useDateGrid显示数据
myCommand = New OleDbCommand( "select * FROM Authors", myConnection )
MyDataGrid.DataSource=myCommand.Executereader()
MyDataGrid.DataBind()
서브 끝
</script>
<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"
GridLines="둘 다"
셀패딩="3"
셀 간격="0"
글꼴 이름="베르다나"
글꼴 크기="10pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
>
</asp:DataGrid>
</body>
</html>