![]() <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd <html xmlns="http://www.w3.org/1999/xhtml <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div id="img" style="position:absolute;"> <a href="http://www.hao123.com/ <img src="fudong.jpg"; border="0"/></a> </div> <SCRIPT LANGUAGE="JavaScript"> <!-- var xPos = 20; var yPos = document.body.clientHeight; var step = 1; var delay = 30; var height = 0; var Hoffset = 0; var Woffset = 0; var yon = 0; var xon = 0; var pause = true; var interval; img.style.top = yPos; function changePos() { width = document.body.clientWidth; height = document.body.clientHeight; Hoffset = img.offsetHeight; Woffset = img.offsetWidth; img.style.left = xPos + document.body.scrollLeft; img.style.top = yPos + document.body.scrollTop; if (yon) { yPos = yPos + step; } else { yPos = yPos - step; } if (yPos < 0) { yon = 1; yPos = 0; } if (yPos >= (height - Hoffset)) { yon = 0; yPos = (height - Hoffset); } if (xon) { xPos = xPos + step; } else { xPos = xPos - step; } if (xPos < 0) { xon = 1; xPos = 0; } if (xPos >= (width - Woffset)) { xon = 0; xPos = (width - Woffset); } } function www_helpor_net() { img.visibility = "visible"; interval = setInterval('changePos()', delay); } www_helpor_net(); //For more,visit:www.helpor.net --> </script> <div> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button2" runat="server" Text="创建数据库" /><br /> <br /> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button3" runat="server" Text="添加一条记录" /><br /> <br /> <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <asp:Button ID="button4" runat="server" Text="添加第二条记录" /><br /> <br /> <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button5" runat="server" Text="更新" /><br /> <br /> <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button6" runat="server" Text="删除" /></div> </form> </body> </html> Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim myConnection As SqlConnection Dim myCommand As SqlCommand Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click myConnection = New SqlConnection("server=(local);database=888;uid=sa;pwd=") myConnection.Open() 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() Label2.Text = "New table created!" myConnection.Close() End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click myConnection = New SqlConnection("server=(local);database=888;uid=sa;pwd=") myConnection.Open() myCommand = New SqlCommand("Insert into [test] (name,sex) values( '黄志文','男' )", myConnection) myCommand.ExecuteNonQuery() Label3.Text = "New Record Inserted!" myConnection.Close() End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button4.Click myConnection = New SqlConnection("server=(local);database=888;uid=sa;pwd=") myConnection.Open() myCommand = New SqlCommand("Insert into [test] (name,sex) values( '李明','男' )", myConnection) myCommand.ExecuteNonQuery() Label4.Text = "New Record Inserted!" myConnection.Close() End Sub Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click myConnection = New SqlConnection("server=(local);database=888;uid=sa;pwd=") myConnection.Open() myCommand = New SqlCommand("UPDATE [test] SET name='Smith' where name='李明'", myConnection) myCommand.ExecuteNonQuery() Label5.Text = "Record Updated!" myConnection.Close() End Sub Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button6.Click myConnection = New SqlConnection("server=(local);database=888;uid=sa;pwd=") myConnection.Open() myCommand = New SqlCommand("delete from [test] where name='Smith'", myConnection) myCommand.ExecuteNonQuery() Label6.Text = "Record Deleted!" myConnection.Close() End Sub
End class
|
asp.net与sql连接的代码
最新推荐文章于 2024-08-05 14:35:00 发布