最初的时候,数据库中的类型是nchar类型的。后来我把数据库中的类型改成了varchar类型的!最初的时候可以注册的!但是改变之后就不能注册了!
提示信息如下:
我插入的信息是字符串类型的!是不是哪里出错了!请高手帮忙看看!应该怎么弄啊!怎么改啊?代码什么的我都没有变过!“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------将截断字符串或二进制数据。
语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 将截断字符串或二进制数据。
语句已终止。源错误:
行 79: string SQLCMDText = "INSERT INTO [member] (username,password,question,answer,realname,sex,borntime,tel,qq,email) VALUES ('" + username_input + "','" + password_input + "','" + question_input + "','" + answer_input + "','" + realname_input + "','" + sex_reg_input + "','" + borntime_input + "','" + tel_input + "','" + qq_input + "','" + email_input + "')";
行 80: SqlCommand theRegCommand = new SqlCommand(SQLCMDText, theCon);
行 81: theRegCommand.ExecuteNonQuery();
行 82: Session["theUser"] = username_input;
行 83: Response.Redirect("Reg_Success.aspx");这是插入的那段数据库的那段代码,麻烦大家帮着看看!theCon.Open();
string username_input = username_reg.Text.ToString();
string password_input = password_reg_1.Text.ToString();
string question_input = question_reg.SelectedItem.Text.ToString();
string answer_input = answer_reg.Text.ToString();
string realname_input = realname_reg.Text.ToString();
//***************************************************************************************************************************
string sex_reg_input = "";
if (sex_man_reg.Checked == true)
{
sex_reg_input = sex_man_reg.Text;
}
if (sex_women_reg.Checked == true)
{
sex_reg_input = sex_women_reg.Text;
}
if (sex_secret_reg.Checked == true)
{
sex_reg_input = sex_secret_reg.Text;
}
//***************************************************************************************************************************
string borntime_input = borntime_reg.SelectedValue.ToString();
string tel_input = tel_reg.Text.ToString();
string qq_input = qq_reg.Text.ToString();
string email_input = email_reg.Text.ToString();
//***************************************************************************************************************************
string SQLCMDText = "INSERT INTO [member] (username,password,question,answer,realname,sex,borntime,tel,qq,email) VALUES ('" + username_input + "','" + password_input + "','" + question_input + "','" + answer_input + "','" + realname_input + "','" + sex_reg_input + "','" + borntime_input + "','" + tel_input + "','" + qq_input + "','" + email_input + "')";
SqlCommand theRegCommand = new SqlCommand(SQLCMDText, theCon);
theRegCommand.ExecuteNonQuery();
Session["theUser"] = username_input;
Response.Redirect("Reg_Success.aspx");
提示信息如下:
我插入的信息是字符串类型的!是不是哪里出错了!请高手帮忙看看!应该怎么弄啊!怎么改啊?代码什么的我都没有变过!“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------将截断字符串或二进制数据。
语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 将截断字符串或二进制数据。
语句已终止。源错误:
行 79: string SQLCMDText = "INSERT INTO [member] (username,password,question,answer,realname,sex,borntime,tel,qq,email) VALUES ('" + username_input + "','" + password_input + "','" + question_input + "','" + answer_input + "','" + realname_input + "','" + sex_reg_input + "','" + borntime_input + "','" + tel_input + "','" + qq_input + "','" + email_input + "')";
行 80: SqlCommand theRegCommand = new SqlCommand(SQLCMDText, theCon);
行 81: theRegCommand.ExecuteNonQuery();
行 82: Session["theUser"] = username_input;
行 83: Response.Redirect("Reg_Success.aspx");这是插入的那段数据库的那段代码,麻烦大家帮着看看!theCon.Open();
string username_input = username_reg.Text.ToString();
string password_input = password_reg_1.Text.ToString();
string question_input = question_reg.SelectedItem.Text.ToString();
string answer_input = answer_reg.Text.ToString();
string realname_input = realname_reg.Text.ToString();
//***************************************************************************************************************************
string sex_reg_input = "";
if (sex_man_reg.Checked == true)
{
sex_reg_input = sex_man_reg.Text;
}
if (sex_women_reg.Checked == true)
{
sex_reg_input = sex_women_reg.Text;
}
if (sex_secret_reg.Checked == true)
{
sex_reg_input = sex_secret_reg.Text;
}
//***************************************************************************************************************************
string borntime_input = borntime_reg.SelectedValue.ToString();
string tel_input = tel_reg.Text.ToString();
string qq_input = qq_reg.Text.ToString();
string email_input = email_reg.Text.ToString();
//***************************************************************************************************************************
string SQLCMDText = "INSERT INTO [member] (username,password,question,answer,realname,sex,borntime,tel,qq,email) VALUES ('" + username_input + "','" + password_input + "','" + question_input + "','" + answer_input + "','" + realname_input + "','" + sex_reg_input + "','" + borntime_input + "','" + tel_input + "','" + qq_input + "','" + email_input + "')";
SqlCommand theRegCommand = new SqlCommand(SQLCMDText, theCon);
theRegCommand.ExecuteNonQuery();
Session["theUser"] = username_input;
Response.Redirect("Reg_Success.aspx");
语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息: System.Data.SqlClient.SqlException: 将截断字符串或二进制数据。
语句已终止。
"很典型,楼主未搞清楚NVARCHAR及VARCHAR的区别.
简单说一下.一段中文字符"中华人民共和国"7个中文字,NVARCHAR(7)就可以解决,而VARCHAR需要14位.
所以会出现字串被截取的情况.
question_input
answer_input
你在测试的时候要注意输入的内容长度会不会超过数据库限定的varchar长度,并且要养成良好的习惯,
对输入的字符长度在程序中先做判断,就可以避免出现这种问题。