asp.net c# 为什么用户名可以重复注册,我的代码有什么问题
using System;
using System.Collections;
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;
namespace 网站
{
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string RUserName = this.RUserName.Text;
string RPwd = this.RPwd.Text;
string REmail = this.REmail.Text;
string RCompany = this.RCompany.Text;
string RAddress = this.RAddress.Text;
string RStorey = this.RStorey.Text;
string RHeight = this.RHeight.Text;
string RArea = this.RArea.Text;
string RFireRating = this.RFireRating.Text;
string RPrincipal = this.RPrincipal.Text;
string RPrincipalTel = this.RPrincipalTel.Text;
string RCustodian = this.RCustodian.Text;
string RCustodianTel = this.RCustodianTel.Text;
string ROthers = this.ROthers.Text;
string Sqlstr2 = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(Sqlstr2);
con.Open();
string sql = @"insert into [cUser] (cName,cPassword,cEmail,cCompany,cAddress,cStorey,cHeight,cArea,
cFireResistanceRating,cPrincipal,cPrincipalTel,cCustodian,cCustodianTel,cOtherInformation) values
('" + RUserName + "','" + RPwd + "','" + REmail + "','" + RCompany + "','" + RAddress + "','" + RStorey + "','" + RHeight + "','" + RArea + "','" + RFireRating + "','" + RPrincipal + "','" + RPrincipalTel + "','" + RCustodian + "','" + RCustodianTel + "','" + ROthers + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
Response.Write("<script type='text/javascript' language='javascript'>alert('注册成功!');</script>");
con.Close();
Server.Transfer("login.aspx");
return;
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string RUserName = args.Value;
string Sqlstr3 = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(Sqlstr3);
con.Open();
string sql1 = "select Count(*) from cUser where cName='" + RUserName + "'";
SqlCommand cmd1 = new SqlCommand(sql1, con);
int count = Convert.ToInt32(cmd1.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}