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

首頁 > 編程 > .NET > 正文

asp.net連接sql數據庫實例基礎教程

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

以下代碼演示了如何使用asp.net連接sql server2000數據庫并操作的代碼實例, 和asp.net初學者分享一下.

asp.net基礎教程,連接sql server2000數據庫實例代碼分析:

以下為代碼內容:
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<script laguage="vb" runat="server">
sub page_load(sender as object,e as eventargs)
dim myconnection as sqlconnection
dim mycommand as sqlcommand
dim ds as dataset
'1.connect to sql server
myconnection = new sqlconnection( "server=localhost;database=pubs;uid=ueytjdf;pwd=doekdf" )
myconnection.open()
la1.text="connection opened!"
 
'2.create a table
mycommand = new sqlcommand( "create table [test] ([id] [int] identity (1, 1) not null ,[name]
 
[char] (10) collate chinese_prc_ci_as null ,[sex] [char] (10) collate chinese_prc_ci_as null
 
)", myconnection )
mycommand.executenonquery()
la2.text="new table created!"
 
'2 添加紀錄
mycommand = new sqlcommand( "insert into [test] (name,sex) values( '黃志文','男' )",
 
myconnection )
mycommand.executenonquery()
la3.text="new record inserted!"
 
'3 更新數據
mycommand = new sqlcommand( "update [test] set name='smith' where name='李明'", myconnection )
mycommand.executenonquery()
la4.text="record updated!"
 
'4 刪除數據
mycommand = new sqlcommand( "delete from [test] where name='smith'", myconnection )
mycommand.executenonquery()
la5.text="record deleted!"
 
'5 用datagrid顯示數據
mycommand = new sqlcommand( "select * from [test]", 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:label id="la5" 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>


國內最大的酷站演示中心!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嫩江县| 宽甸| 晋城| 宁津县| 偃师市| 昔阳县| 肇州县| 奉节县| 恭城| 黄梅县| 泸水县| 曲靖市| 龙陵县| 九台市| 鹰潭市| 长沙市| 华安县| 虹口区| 江安县| 柳江县| 于都县| 宁津县| 锦州市| 疏附县| 甘谷县| 平泉县| 平舆县| 祥云县| 灌南县| 澳门| 平安县| 临漳县| 昌邑市| 霍林郭勒市| 沧源| 汾西县| 定边县| 永丰县| 内黄县| 闸北区| 峨边|