asp.net与sql连接的代码

 


default.aspx的代码
<%@ 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/"; target="_blank">
<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>
        &nbsp;<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>



default.aspx.vb的代码

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值