首页 > 编程 > ASP > 正文

我的第一个ASP+程序,如果是新手请进来看吧。谢绝高手。:)

2024-05-04 11:06:28
字体:
来源:转载
供稿:网友


<!--我的第一个asp+程序-->
<!--如有转载,请注明出处! 作者:大自然 主页:http://zhanzhen.wayall.com 欢迎来信[email protected]指教-->
<!--作者瞎写:这么一段程序可是花了我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
</script>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表