首页新闻找找看学习计划

关于 注册模块 的一个问题

0
[待解决问题]

请问:我按教程在做一个注册的倒子,然后调试的时候老是提示是 注册错误,我贴上代码,请帮看下一吧。谢谢
ASPX:


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 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">
<link href ="css.css" rel ="Stylesheet" type ="text/css" />
<style type ="text/css" >

.style1
{
 width :100%
}

.style2
{
}

.style3
{
 width :175px;
}

.style4
{
 color :#ff3300;
}

.style5
{
 color :#ff0000;
}

.style6
{
 width :102px;
}

</style>
    <title>注册</title>
</head>
<body>
    <form id="form1" runat="server">
    <div class ="top "></div>
    <div class ="register ">
    <table class ="style1 " >
    <tr>
        <td>用户名:</td><td class ="style3">
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </td><td>&nbsp;<span class  ="style4">*</span>&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                            ControlToValidate="TextBox1" ErrorMessage="必须输入用户名!"></asp:RequiredFieldValidator>
                    </td>
    </tr>
    <tr>
        <td>密码:</td><td class ="style3">
                    <asp:TextBox ID="TextBox2" runat="server" TextMode  ="Password" ></asp:TextBox>
                    </td><td>&nbsp;<span class ="style4">*</span>&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                            ControlToValidate="TextBox2" ErrorMessage="必须输入密码"></asp:RequiredFieldValidator>
                    </td>
    </tr>
    <tr>
        <td>性别:</td><td class ="style3">
                    <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem>帅哥</asp:ListItem>
                        <asp:ListItem>美女</asp:ListItem>
                        <asp:ListItem>保密</asp:ListItem>
                    </asp:DropDownList>
                    </td><td> &nbsp;<span class ="style4">*</span>&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                            ControlToValidate="DropDownList1" ErrorMessage="必须选择性别!"></asp:RequiredFieldValidator>
                    </td>
    </tr>
    <tr>
        <td>头像:</td><td class ="style3">
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                    </td>
    </tr>
    <tr>
        <td>IM:</td><td class ="style3">
                    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                    </td>
    </tr>
    <tr>
        <td>个性签名:</td><td class ="style3">
                    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                    </td>
    </tr>
    <tr>
        <td>备注:</td><td class ="style3">
                    <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
                    </td>
    </tr>
    <tr>
        <td colspan ="3">
            <asp:Button ID="Button1" runat="server" Text="注册" onclick="Button1_Click" />
            <asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
        </td>
    </tr>
    </table>
    </div>
    <div class ="end ">版权信息 本网站不会将用户信息泄露给任何人或机构!</div>
    </form>
</body>
</html>

 


ASPX.CS:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected bool Check(string text)
    {
        if (text.Contains("<") || text.Contains(">") || text.Contains("'") || text.Contains("//") || text.Contains("\\"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Check(TextBox1.Text ) || Check(TextBox2.Text ) || Check(TextBox3.Text ) || Check(TextBox4.Text ) || Check(TextBox5.Text )
            || Check(TextBox6.Text ))
        {
            Label8.Text = "注册错误,含有非法字符,请重新输入!";
        }
        else
        {

            try
            {
                SqlConnection con = new SqlConnection("server='(local)';database='Register';uid='sa';pwd='sa'");
                con.Open();
                string strsql = "insert into Register(username,password,sex,picture,im,information,others,ifisuser) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.Text  + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "',0)";
                SqlCommand cmd = new SqlCommand(strsql, con);
                cmd.ExecuteNonQuery();
                Label8.Text = "注册成功,请牢记你的注册信息!";
            }
            catch
            {
                Label8.Text = "注册失败,请重新注册!";
            }
        }
    }
}

 

sql:

USE [Register]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Register](
 [id][int] IDENTITY(1,1) NOT NULL,
 [username][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL ,
 [password][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
 [sex][int] NULL,
 [picture][nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 [IM][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
 [information][nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 [others][nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
 [ifisuser][int] NULL,
 CONSTRAINT [PK_Register] PRIMARY KEY CLUSTERED
(
 [id] ASC
)
 WITH (PAD_INDEX =OFF ,STATISTICS_NORECOMPUTE=OFF ,IGNORE_DUP_KEY=OFF , ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]

)ON[PRIMARY]

 

注册时,填入注册信息,老是提示:注册失败,请重新注册!

wmaco的主页 wmaco | 初学一级 | 园豆:200
提问于:2010-12-09 15:12
< >
分享
所有回答(4)
0

单步调试啊。。。

顾晓北 | 园豆:9880 (大侠五级) | 2010-12-09 15:35
0

帅哥,把你的表结构贴出来

wlz0815 | 园豆:587 (小虾三级) | 2010-12-09 16:59
0

一楼正解,断点调试就Ok

Tester Chen | 园豆:1690 (小虾三级) | 2010-12-09 20:44
0

你把出错的地方贴出来就可以了。

Astar | 园豆:40805 (高人七级) | 2010-12-11 06:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册