<!--我的第一个ASP+程序-->
<!--如有转载,请注明出处! 作者:大自然 主页:http://zhanzhen.wayall.com 欢迎来信zhanmr@telekbird.com.cn指教-->
<!--作者瞎写:这么一段程序可是花了我N长时间啊。。唉。。主要是对ADO+了解不太深,一开始为了节省系统资源,所以用了DataReader,后来发现原来功能这差的,就改用DataSet,唉。。用惯了原来的ADO模式,一下子真是不适应:(,还有那个VS7,虽然写起ASP+来还算方便,不过好像很容易崩溃,不过有点好就是崩掉后会马上重新启动程序。:)-->
<!--程序功能:利用ASP+中的Panel这个WEB CONTROL来实现三个窗口的切换,从而使我们原告在ASP里要用三张页面实现的功能(如果硬凑在一张也是可以的,不过不要太复杂哦)现在只要一张页面就能完事了。然后用ADO+的DataSet和DataTable控件来完成对数据库的操作-->
<!--
前期工作:在SQL SERVER里建立一个mytest数据库,然后把这段放到Sql Query Analyzer里运行一下
CREATE TABLE [dbo].[tb_User] (
[intID] [int] IDENTITY (1, 1) NOT NULL ,
[vcUserID] [varchar] (20) NOT NULL ,
[vcPassWord] [varchar] (20) NOT NULL ,
[vcName] [varchar] (20) NULL ,
[vcTel] [varchar] (20) NULL ,
[vcAddr] [varchar] (50) NULL
) ON [PRIMARY]
GO
然后你可以插入几条测试数据就行了,我也是ASP+的新手,希望能互相学习,一起提高:)
-->
<%@ import Namespace="System.Data.ADO" %>
<%@ import Namespace="System.Data" %>
<html>
<head>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<title>修改个人基本信息</title>
</head>
<body>
<form id="PanelSC" method="post" runat="server">
<!--登录窗口-->
<asp:panel id="Step1" runat="Server">
步骤一: (请输入帐号及密码)<p>
<blockquote>
帐号: <asp:textbox id=UserID runat="server"></asp:textbox><p>
密码: <asp:textbox id=PassWord runat="Server" textmode="Password"></asp:textbox><p>
<input id=Button1 type=button value=" 登入 " runat="server" onserverclick="Button1_Click"></p>
</blockquote>
<div id="div1" runat="server"></div>
</asp:panel>
<!--修改窗口-->
<asp:panel id="Step2" runat="Server">
步骤二: (请修改姓名、电话、地址)<p>
<blockquuote>
姓名: <asp:textbox id=Name runat="Server" text=""></asp:textbox><p>
电话: <asp:textbox id=Tel runat="Server" text=""></asp:textbox><p>
地址: <asp:textbox id=Addr runat="Server" text=""></asp:textbox><p>
<input id=Button2 type=button value=" 修改 " runat="server" onserverclick="Button2_Click">
</blockquote>
<div id="div2" runat="server"></div>
</asp:panel>
<!--确认窗口-->
<asp:panel id="Step3" runat="Server">
步骤三: (请确认您输入的数据)<p>
<blockquote>
<div id="div3" runat="server"></div>
<input id=Button3 type=button value=" 确定 " runat="server" onserverclick="Button3_Click">
</blockquote>
</asp:panel>
<!--成功窗口-->
<asp:panel id="Step4" runat="Server">
<blockquote>
<div id="div4" runat="server"></div>
</blockquote>
</asp:panel>
</form>
</body>
</html>
<script language="vb" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Step1.Visible = True
Step2.Visible = False
Step3.Visible = False
End If
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
Dim ConnStr,SqlQuery As String
Dim i As Integer = 0
ConnStr = "Driver={SQL Server}; Server=localhost; Uid=sa; pwd=; database=mytest"
SqlQuery = "Select vcName, vcTel, vcAddr From tb_User Where vcUserID = '" & UserID.Text & "' And vcPassWord = '" & PassWord.Text & "'"
Dim Cmd As ADODataSetCommand = New ADODataSetCommand(SqlQuery, ConnStr)
Dim Rs As DataSet = New DataSet()
Cmd.FillDataSet(Rs, "tb_User")
Dim Dt As DataTable = Rs.Tables("tb_User")
i = Dt.Rows.Count
If i = 1 Then
Name.Text = Dt.Rows(0).Item(0)
Tel.Text = Dt.Rows(0).Item(1)
Addr.Text = Dt.Rows(0).Item(2)
Step1.Visible = False
Step2.Visible = True
Step3.Visible = False
Else
Step1.Visible = True
Step2.Visible = False
Step3.Visible = False
div1.innerHtml = "登录失败!请检查你的帐号和密码是否正确!"
End If
End Sub
Sub Button2_Click(sender As Object, e As EventArgs)
Step1.Visible = False
Step2.Visible = False
Step3.Visible = True
div3.innerHtml = "帐号:" & UserId.Text & "<br>"
div3.innerHtml &= "姓名:" & Name.Text & "<br>"
div3.innerHtml &= "电话:" & Tel.Text & "<br>"
div3.innerHtml &= "地址:" & Addr.Text & "<p>"
End Sub
Sub Button3_Click(sender As Object, e As EventArgs)
Dim ConnStr, SqlQuery As String
ConnStr = "Driver={SQL Server}; Server=localhost; Uid=sa; pwd=; database=mytest"
SqlQuery = "Update tb_User Set vcName = '" & Name.Text & "', vcTel = '" & Tel.Text & "', vcAddr = '" & Addr.Text & "'"
Dim Cmd As ADOCommand = New ADOCommand(SqlQuery, ConnStr)
Cmd.ActiveConnection.Open()
Cmd.Execute()
If Cmd.RecordsAffected = 1 Then
div4.innerHtml = "你的个人资料已经被正确修改!<a href=""PanelSC.aspx"">按此返回登录</a>"
Else
div4.innerHtml = "发生错误!<a href=""
javascript:history.back(-1)"">按此返回重新修改</a>"
End If
End Sub
</scrip
……