FirstWeb连接数据库中的数据

作业:实现用户注册功能
要求:
1.注册内容包括:用户名,密码,姓名,地址,手机,出生年月,性别,邮箱
2.注册时验证用户名是否存在
3.出生年月日让用户选择,而不是手动输入

前台 在浏览器中查看  (自己写)

--将年月写死,用javascript可以实现年月

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyWeb.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">
    <table>
    <tr><td>
        <asp:Label ID="txtUserName" runat="server" Text="用户名:"></asp:Label></td><td>
            <asp:TextBox ID="txbUserName" runat="server"></asp:TextBox></td></tr>
                <tr><td>
        <asp:Label ID="txtPwd" runat="server" Text="密码:"></asp:Label></td><td>
            <asp:TextBox ID="txbPwd" runat="server"></asp:TextBox></td></tr>
                <tr><td>
        <asp:Label ID="txtName" runat="server" Text="姓名:"></asp:Label></td><td>
            <asp:TextBox ID="txbName" runat="server"></asp:TextBox></td></tr>
                <tr><td>
        <asp:Label ID="txtAddress" runat="server" Text="地址:"></asp:Label></td><td>
            <asp:TextBox ID="txbAddress" runat="server"></asp:TextBox></td></tr>
                <tr><td>
        <asp:Label ID="txtPhone" runat="server" Text="手机号:"></asp:Label></td><td>
            <asp:TextBox ID="txbPhone" runat="server"></asp:TextBox></td></tr>
            <tr><td>
                <asp:Label ID="txtBrithday" runat="server" Text="出生年月:"></asp:Label></td><td>
                    <asp:DropDownList ID="DropDownBrithday" runat="server">
                        <asp:ListItem>1993-01</asp:ListItem>
                        <asp:ListItem>1993-02</asp:ListItem>
                        <asp:ListItem>1993-03</asp:ListItem>
                        <asp:ListItem>1993-04</asp:ListItem>
                        <asp:ListItem>1993-05</asp:ListItem>
                        <asp:ListItem>1993-06</asp:ListItem>
                        <asp:ListItem>1993-07</asp:ListItem>
                        <asp:ListItem>1993-08</asp:ListItem>
                        <asp:ListItem>1993-09</asp:ListItem>
                        <asp:ListItem>1993-10</asp:ListItem>
                        <asp:ListItem>1993-11</asp:ListItem>
                        <asp:ListItem>1993-12</asp:ListItem>
                    </asp:DropDownList>
                </td></tr>
                <tr><td>
        <asp:Label ID="txtGender" runat="server" Text="性别:"></asp:Label></td><td>
            <asp:TextBox ID="txbGender" runat="server"></asp:TextBox></td></tr>
                <tr><td>
        <asp:Label ID="txtE_mail" runat="server" Text="邮箱:"></asp:Label></td><td>
            <asp:TextBox ID="txbE_mail" runat="server"></asp:TextBox></td></tr>
            <tr><td>
                <asp:Button ID="btnLogon" runat="server" Text="注册" οnclick="btnLogon_Click" /></td><td>
                    <asp:Label ID="txtLable" runat="server" Text=""></asp:Label></td><td>
                        <asp:Label ID="txtLabel2" runat="server" Text=""></asp:Label></td></tr>
    </table>
    </form>
</body>
</html>

后台连接数据库

  protected void btnLogon_Click(object sender, EventArgs e)
        {
            string sqlserver = "Data Source=SXVPTNJT9Q07YYP;Initial Catalog=MyWeb;User ID=sa;Password=abcdef";
            SqlConnection conn = new SqlConnection(sqlserver);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select count(*) from T_myweb where UserName=@UserName";
            cmd.Parameters.AddWithValue("@UserName", txbUserName.Text);
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (result > 0)
            {
                txtLable.Text = "已经存在相同用户名!";
            }
            else
            {
                cmd.Parameters.AddWithValue("UserName", txbUserName.Text);
                cmd.Parameters.AddWithValue("tpassWord", txbPwd.Text);
                cmd.Parameters.AddWithValue("Name", txbName.Text);
                cmd.Parameters.AddWithValue("tAddress", txbAddress.Text);
                cmd.Parameters.AddWithValue("Phone", txbPhone.Text);
                cmd.Parameters.AddWithValue("Brithday", DropDownBrithday.Text);
                cmd.Parameters.AddWithValue("Gender", txbGender.Text);
                cmd.Parameters.AddWithValue("E_mail", txbE_mail.Text);
              //  string email1 = txbE_mail.Text;
               // string[] email = email1.Split('@');
                 //    foreach (string item in email)
                   //      {
                     //        if (email.Length > 0)
                       //      {
                         //        txtLabel2.Text = item;
                           //  }
                        // }
              
                txtLable.Text = "注册成功!";
            }
        }

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值