国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 連接數據庫基礎

2024-07-10 13:03:06
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

'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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 纳雍县| 韩城市| 平陆县| 沂南县| 赣榆县| 新蔡县| 抚顺县| 漯河市| 琼结县| 治多县| 中卫市| 宁河县| 涞水县| 长顺县| 玉溪市| 万山特区| 元阳县| 观塘区| 余庆县| 东乌珠穆沁旗| 彝良县| 丰镇市| 灌南县| 南部县| 竹北市| 中西区| 灵武市| 怀柔区| 贺兰县| 利辛县| 泗阳县| 铜川市| 双江| 尤溪县| 伊吾县| 深圳市| 津南区| 柳河县| 郓城县| 东乡族自治县| 桃江县|