用.net2005和sql2005,c#写的B/S结构新用户注册页面
出的问题是使用数字注册就正常,可以输入到数据库
但是一输入英文就提示错误
大家帮帮忙,看看是那里的问题.
数据库用的是nchar(30)的数据类型以下是代码using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class NewCustomer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CompareValidator1.ControlToValidate = "tb_Password";
CompareValidator1.ControlToCompare = "tb_Password_t";
CompareValidator1.Text = "密码不一致,请重新输入";
}
protected void bt_Insert_Click(object sender, EventArgs e)
{
String s_CustomerID = tb_CustomerID.Text.Trim();
String s_Password = tb_Password.Text.Trim();
String s_PhoneNumber = tb_PhoneNumber.Text.Trim();
String s_Adress = tb_Adress.Text.Trim();
String s_PasswordQuestion = tb_PasswordQuestion.Text.Trim();
String s_answer = tb_answer.Text.Trim();
lb_Info.Text = "";
if (s_CustomerID == "" || s_Password == "" || s_PhoneNumber == "" || s_Adress == "" || s_PasswordQuestion == "" || s_answer == "")
{
lb_Info.Text = "注册信息不能为空,请全部填写";
}
else
{
String strContion = "Data Source=WWW-3E180DC04B4;Initial Catalog=Rysm;Integrated Security=True";
SqlConnection con = new SqlConnection(strContion);
String sql = ("INSERT INTO c_detail(CustomerID,Password,PhoneNumber,Adress,PasswordQuestion,answer)VALUES(" + s_CustomerID + "," + s_Password + "," + s_PhoneNumber + "," + s_Adress + "," + s_PasswordQuestion + "," + s_answer + ")");
SqlCommand com = new SqlCommand(sql, con);
try
{
com.Connection.Open();
com.ExecuteNonQuery();
com.Connection.Close();
lb_Info.Text = "注册成功";
}
catch (Exception es)
{
lb_Info.Text = "注册出错,错误信息: " + es.Message;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Login.aspx");
}
}
出的问题是使用数字注册就正常,可以输入到数据库
但是一输入英文就提示错误
大家帮帮忙,看看是那里的问题.
数据库用的是nchar(30)的数据类型以下是代码using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class NewCustomer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CompareValidator1.ControlToValidate = "tb_Password";
CompareValidator1.ControlToCompare = "tb_Password_t";
CompareValidator1.Text = "密码不一致,请重新输入";
}
protected void bt_Insert_Click(object sender, EventArgs e)
{
String s_CustomerID = tb_CustomerID.Text.Trim();
String s_Password = tb_Password.Text.Trim();
String s_PhoneNumber = tb_PhoneNumber.Text.Trim();
String s_Adress = tb_Adress.Text.Trim();
String s_PasswordQuestion = tb_PasswordQuestion.Text.Trim();
String s_answer = tb_answer.Text.Trim();
lb_Info.Text = "";
if (s_CustomerID == "" || s_Password == "" || s_PhoneNumber == "" || s_Adress == "" || s_PasswordQuestion == "" || s_answer == "")
{
lb_Info.Text = "注册信息不能为空,请全部填写";
}
else
{
String strContion = "Data Source=WWW-3E180DC04B4;Initial Catalog=Rysm;Integrated Security=True";
SqlConnection con = new SqlConnection(strContion);
String sql = ("INSERT INTO c_detail(CustomerID,Password,PhoneNumber,Adress,PasswordQuestion,answer)VALUES(" + s_CustomerID + "," + s_Password + "," + s_PhoneNumber + "," + s_Adress + "," + s_PasswordQuestion + "," + s_answer + ")");
SqlCommand com = new SqlCommand(sql, con);
try
{
com.Connection.Open();
com.ExecuteNonQuery();
com.Connection.Close();
lb_Info.Text = "注册成功";
}
catch (Exception es)
{
lb_Info.Text = "注册出错,错误信息: " + es.Message;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Login.aspx");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货