熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net連接Access數據庫

2022-06-13   來源: .NET編程 

<%@ 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>


From:http://tw.wingwit.com/Article/program/net/201311/15614.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.