欢迎光临
我们一直在努力

asp.net连接Access数据库例子-.NET教程,数据库应用

建站超值云服务器,限时71元/月

asp.net连接access数据库
<%@ import namespace=”system.data” %>
    <%@ import namespace=”system.data.oledb” %>
    <script laguage=”vb” runat=”server”>
    dim myconnection as oledbconnection
    dim mycommand as oledbcommand
    sub page_load(sender as object,e as eventargs)

    1.连接数据库
    dim dbname as string
    dbname=server.mappath(“authors.mdb”)
    myconnection = new oledbconnection( “provider=microsoft.jet.oledb.4.0;data source=”&dbname )
    myconnection.open()
    la1.text=”connection opened!”

 

    2.添加记录
    mycommand = new oledbcommand( “insert into authors(authors,country) values(simson,usa)”, myconnection )
    mycommand.executenonquery()
    la2.text=”new record inserted!”

 

    3 更新数据(access)
    mycommand = new oledbcommand( “update authors set authors=bennett where authors = simson”, myconnection )
    mycommand.executenonquery()
    la3.text=”record updated!”

 

    4 删除数据(access)
    mycommand = new oledbcommand( “delete from authors where authors = david”, myconnection )
    mycommand.executenonquery()
    la4.text=”record deleted!”

 

    5 使用dategrid显示数据
    mycommand = new oledbcommand( “select * from authors”, myconnection )
    mydatagrid.datasource=mycommand.executereader()
    mydatagrid.databind()

 

    end sub
    </script>
    <html>
    <body>
    <asp:label id=”la1″ runat=”server” /><br>
    <asp:label id=”la2″ runat=”server” /><br>
    <asp:label id=”la3″ runat=”server” /><br>
    <asp:label id=”la4″ runat=”server” /><br>
    <asp:datagrid id=”mydatagrid” runat=”server”
    bordercolor=”black”
    borderwidth=”1″
    gridlines=”both”
    cellpadding=”3″
    cellspacing=”0″
    font-name=”verdana”
    font-size=”10pt”
    headerstyle-backcolor=”#aaaadd”
    alternatingitemstyle-backcolor=”#eeeeee”
    >
    </asp:datagrid>

    </body>
    </html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp.net连接Access数据库例子-.NET教程,数据库应用
分享到: 更多 (0)