这个问题在这里已有答案:
-
What is a NullReferenceException, and how do I fix it? 32个答案
-
后面的代码 -
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update member_reg_tbl set full_name='" + TextBox3.Text + "', gender ='" + RadioButtonList1.SelectedItem.Text + "', dob='" + TextBox4.Text + "', occupation='" + TextBox5.Text + "', education='" + TextBox6.Text + "', mobile_number='" + TextBox7.Text + "', landline_number='" + TextBox8.Text + "', country='" + DropDownList3.SelectedItem.Text + "', state='" + DropDownList4.SelectedItem.Text + "', district='" + TextBox14.Text + "', city='" + DropDownList6.SelectedItem.Text + "', email_id='" + TextBox9.Text + "', address='" + TextBox10.Text + "', password='" + TextBox12.Text + "', retype_password='" + TextBox13.Text + "',image='" + path + "' where user_id='"+Label22.Text+"'";
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Label21.Text = ""+Label22.Text+"Updated successfully..press cancel to login";
- 错误 -
异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例 .
来源错误:
第102行:
第103行:SqlCommand cmd = new SqlCommand();第104行:cmd.CommandText = "update member_reg_tbl set full_name='" TextBox3.Text "', gender ='" RadioButtonList1.SelectedItem.Text "', dob='" TextBox4.Text "', occupation='" TextBox5.Text "', education='" TextBox6.Text "', mobile_number='" TextBox7.Text "', landline_number='" TextBox8.Text "', country='" DropDownList3.SelectedItem.Text "', state='" DropDownList4.SelectedItem.Text "', district='" TextBox14.Text "', city='" DropDownList6.SelectedItem.Text "', email_id='" TextBox9.Text "', address='" TextBox10.Text "',user_id='" Label22.Text "', password='" TextBox12.Text "', retype_password='" TextBox13.Text "',image='" path "' where user_id='" Label22.Text "'";第105行:cmd.Connection = con;第106行:con.Open();
2 回答
调试代码并确保所有
TextBox
,RadioButtonList
和DropDownList
都有值而不是null,请确保
con
具有正确的连接字符串,并且选择了所有指定的DropDownList
和RadioButtonList
,它应该具有一些值 .