未将对象引用设置到对象的实例??
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 24: using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["CarManage"].ConnectionString))
行 25: {
行 26: using (SqlCommand command = new SqlCommand("insert into UserMessage(UserName,UPassword,UCode,UName,USex,UBir,UMZ,USFZ,UPhone,UBuMen,UAddress,UPerMissions) values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox4.Text + "','" + this.TextBox9.Text + "'," + this.RadioButtonList1.SelectedValue + ",'" + birthday.Value + "','" + DropDownListNation.Items[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox5.Text + "','" + this.TextBox6.Text + "','" + this.bumen.Items[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox7.Text + "','" + RadioButtonList2.SelectedItem.Text + "')"))
行 27: {
行 28: connection.Open();//打开数据库连接
源文件: f:\CarManage\Register.aspx.cs 行: 26
//源文件
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection
(ConfigurationManager.ConnectionStrings["CarManage"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("insert into UserMessage
(UserName,UPassword,UCode,UName,USex,UBir,UMZ,USFZ,UPhone,UBuMen,UAddress,UPerMissio
ns) values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "','" +
this.TextBox4.Text + "','" + this.TextBox9.Text + "'," +
this.RadioButtonList1.SelectedValue + ",'" + birthday.Value + "','" +
DropDownListNation.Items[this.DropDownListNation.SelectedIndex].Text + "','" +
this.TextBox5.Text + "','" + this.TextBox6.Text + "','" + this.bumen.Items
[this.DropDownListNation.SelectedIndex].Text + "','" + this.TextBox7.Text + "','" +
RadioButtonList2.SelectedItem.Text + "')"))
{
connection.Open();
command.Connection = connection;
int result = (int)command.ExecuteNonQuery();
if (result != 0)
{
JScript.AlertAndRedirect("登录成功!", "Login.aspx");
}
else
{
JScript.AlertAndRedirect("登录失败,请重新输入您的用户名和密码!", "#");
}
}
}
}
乞求高手前来赐教