数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

asp.net连接Access数据库


发布日期:2023年12月25日
 
asp.net连接Access数据库

<%@ Import Namespace=SystemData %>

<%@ Import NameSpace=SystemDataOleDb %>

<script laguage=VB runat=server>

Dim myConnection As OleDbConnection

Dim myCommand As OleDbCommand

sub page_load(sender as Objecte as EventArgs)

连接数据库

dim dbname as string

dbname=servermappath(authorsmdb)

myConnection = New OleDbConnection( PROVIDER=MicrosoftJetOLEDB;DATA Source=&dbname )

myConnectionOpen()

latext=Connection Opened!

添加记录

myCommand = New OleDbCommand( Insert INTO Authors(Authorscountry) Values(Simsonusa) myConnection )

myCommandExecuteNonQuery()

latext=New Record Inserted!

更新数据(Access)

myCommand = New OleDbCommand( UPDATE Authors SET Authors=Bennett WHERE Authors = Simson myConnection )

myCommandExecuteNonQuery()

latext=Record Updated!

删除数据(access)

myCommand = New OleDbCommand( DELETE FROM Authors WHERE Authors = David myConnection )

myCommandExecuteNonQuery()

latext=Record Deleted!

使用DateGrid显示数据

myCommand = New OleDbCommand( select * FROM Authors myConnection )

MyDataGridDataSource=myCommandExecutereader()

MyDataGridDataBind()

end sub

</script>

<html>

<body>

<asp:label id=la runat=server /><br>

<asp:label id=la runat=server /><br>

<asp:label id=la runat=server /><br>

<asp:label id=la runat=server /><br>

<ASP:DataGrid id=MyDataGrid runat=server

BorderColor=black

BorderWidth=

GridLines=Both

CellPadding=

CellSpacing=

FontName=Verdana

FontSize=pt

HeaderStyleBackColor=#aaaadd

AlternatingItemStyleBackColor=#eeeeee

>

</asp:DataGrid>

</body>

</html>

上一篇:使用动态数据库访问对象

下一篇:使用嵌套的Repeater控件显示分级数据