域名注册,企业邮局,虚拟主机 用户注册 | 新闻中心 | 用户管理 | 代理管理 | 独立面板 | 交费方式 | 联系我们
科技创造美好生活 您最佳的互联网伙伴
企业邮局 返回首页 域名注册 虚拟主机 企业邮局 网站制作 网站推广 IDC数据 人才招聘

  客户支持相关
常见热门问题
域名相关帮助
空间相关帮助
邮局相关帮助
财务相关帮助
代理相关帮助
网站推广帮助
网站制作相关教程
ASP.net连接SQL Server2000数据库例程
2008-6-21 10:26:44 企星科技 浏览次数
关键字: SQL Server2000 - 本站搜索 - Google搜索 - Baidu搜索 - Yahoo搜索 - sougo搜索
关键字: ASP.net连接SQL Server2000数据库 - 本站搜索 - Google搜索 - Baidu搜索 - Yahoo搜索 - sougo搜索
 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>

关于我们 | 联系我们 | 汇款方式 | 价格总览 | 网站地图 | 合作伙伴 | 常见问题
企星旗下网站: 企星科技 - 星线空间 - 主机托管租用 - 网站建设 - 游戏点卡 - 家族天空 - 网络游戏推广 - 凤舞天骄 - 天骄2活力版 - 净化消毒设备网 - 揭西视窗
深圳搜房网 - 网游联盟 - 网吧联盟 - 粤东人才网 - 中文新闻网 - 天天旅游网 - 非主流交友网 - 网址大全 - 一起去聊天网 - 一品堂论坛 - 股票在线
Copyright © 2000-2008 WWW.86QX.COM All rights reserved
合作伙伴,备案编号:粤ICP备07056730号
企星科技有限公司·中国 版权所有