Asp.net如何连接SQL Server2000数据库
点击次数:20 次 发布日期:2008-11-26 15:48:54 作者:源代码网
|
源代码网推荐 在这里和大家分享一下: 源代码网推荐 源代码网推荐 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> 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
