| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 456 人关注过本帖
标题:注册界面出现问题
只看楼主 加入收藏
rainboworsun
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-5-4
结帖率:100%
收藏
 问题点数:0 回复次数:1 
注册界面出现问题
本人是菜鸟,各位大侠谁能帮忙解决一下此问题(由于没有积分了,也没积分给了)
出现问题地方:int i=Convert.ToInt32(com.ExecuteNonQuery());[在此处出现异常](源码中红色部分)

.aspx源码:
<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 688px; height: 15px">
            <tr>

                <td style="height: 2px" align="right">
                    <asp:Label ID="Label1" runat="server" Text="会员登录名:"></asp:Label></td>
                <td style="width: 341px; height: 2px">
                    <asp:TextBox ID="TextName" runat="server"></asp:TextBox>
                    <asp:Button ID="btmIsName" runat="server" OnClick="btmIsName_Click" Text="检测会员员" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ErrorMessage="必须填写会员名" ControlToValidate="TextName"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>

                <td align="right">
                    <asp:Label ID="Label2" runat="server" Text="密 码:"></asp:Label></td>
                <td style="width: 341px">
                    <asp:TextBox ID="TextPassword" runat="server" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorPwd" runat="server" ControlToValidate="TextPassword"
                        ErrorMessage="密码不能为空"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label3" runat="server" Text="确认密码:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:TextBox ID="TextQrPassword" runat="server" TextMode="Password"></asp:TextBox>
                    <asp:CompareValidator ID="CompareValidatorPass" runat="server" ControlToCompare="TextPassword"
                        ControlToValidate="TextQrPassword" ErrorMessage="两次密码不一致"></asp:CompareValidator></td>
            </tr>
                        <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label4" runat="server" Text="性 别:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:RadioButton ID="RadioButtonMan" runat="server" GroupName="groupSex" Text="男" Checked="True" />
                    <asp:RadioButton ID="RadioButtonWoman" runat="server" GroupName="groupSex" Text="女" /></td>
            </tr>            <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label5" runat="server" Text="真实姓名:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:TextBox ID="TextRelName" runat="server"></asp:TextBox></td>
            </tr>            <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label6" runat="server" Text="电 话:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:TextBox ID="TextPhone" runat="server"></asp:TextBox></td>
            </tr>            <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label7" runat="server" Text="Email:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:TextBox ID="TextEmail" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorTextEmail" runat="server" ErrorMessage="Email不能为空" ControlToValidate="TextEmail"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail" runat="server"
                        ControlToValidate="TextEmail" ErrorMessage="Email格式不正确" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
            </tr>            <tr>

                <td style="height: 14px" align="right">
                    <asp:Label ID="Label8" runat="server" Text="地 址:"></asp:Label></td>
                <td style="width: 341px; height: 14px">
                    <asp:TextBox ID="TextAddress" runat="server"></asp:TextBox></td>
            </tr>            <tr>

                <td style="height: 14px" align="right">
                    <asp:Button ID="btnLogin" runat="server" Font-Size="Small" Text="注 册" OnClick="btmLogin_Click" /></td>
                <td style="width: 341px; height: 14px">
                    <asp:Button ID="btnCancel" runat="server" Font-Size="Small" Text="取 消" /></td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>


其中类源码:
public class DB
{
    public DB()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public static SqlConnection creatSqlCon()
    {
        SqlConnection con = new SqlConnection("Data Source=.;database='userDB';uid='sa';pwd='123' ");
        return con;
    }
}

.aspx.cs源码:
public partial class _Default : System.Web.UI.Page
{
 
    protected int isName()
    {
        int i;
        string name = TextName.Text;
        if (name.Trim() != "")
        {
            SqlConnection con =DB.creatSqlCon();
            con.Open();
            SqlCommand com = new SqlCommand("select count(*) from User_Table where Name='" + name + "'", con);
            return i = Convert.ToInt32(com.ExecuteScalar());
            con.Close();
        }
        else
            return i = 1;
    }
    public bool add()
    {
     string name=TextName.Text;
    string pass=FormsAuthentication.HashPasswordForStoringInConfigFile(TextPassword.Text,"MD5");
    string sex;
    if(RadioButtonMan.Checked)
    {
    sex="男";
    }
    else
    {
    sex="女";
    }
    string trueName=TextRelName.Text;
    string phone=TextPhone.Text;
    string address=TextAddress.Text;
    string email=TextEmail.Text;
    string sql="insert into User_Table values('"+name+"','"+pass+"','"+sex+"','"+trueName+"','"+phone+"','"+email+"','"+address+"')";
    SqlConnection con=DB.creatSqlCon();
    con.Open();
    SqlCommand com=new SqlCommand(sql,con);
    int i=Convert.ToInt32(com.ExecuteNonQuery());[在此处出现异常]
    if(i>0)
    {
        return true;
    }
    else
    {
        return false;
    }
    con.Close();

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btmIsName_Click(object sender, EventArgs e)
    {
        int i=isName();
        if (i >0)
        {
           
            RegisterStartupScript("yes", "<script>alart('会员名已经存在!')</script>");
        }
        else
        {
            RegisterStartupScript("no", "<script>alart('可以注册')</script>");
        }
    }
protected void  btmLogin_Click(object sender, EventArgs e)
{
    int i=isName();
    if (i<=0)
    {
        if (add())
        {
            SqlConnection con = DB.creatSqlCon();
            con.Open();
            SqlCommand com = new SqlCommand("insert User_Longin values('" + TextName.Text + "','" + DateTime.Now.ToString() + "')", con);
            com.ExecuteNonQuery();
            Response.Write("<script>alert('注册成功!单击确定返回登陆页面');location='landing.aspx';</script>");
            con.Close();
        }
        else
            Response.Write("<script>alert('注册失败!')</script>");
    }
    else
    {
        Response.Write("<script>alert('会员名已经存在!')</script>");   
    }
}
}
搜索更多相关主题的帖子: 注册 界面 
2009-09-16 20:25
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
string sql="insert into User_Table values('"+name+"','"+pass+"','"+sex+"','"+trueName+"','"+phone+"','"+email+"','"+address+"')";
   
检查这句是否有问题.

飘过~~
2009-09-16 23:05
快速回复:注册界面出现问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034120 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved