0

プロファイルを保存しようとすると、オブジェクト参照がオブジェクトのインスタンスに設定されていないというエラーが表示されます。

「if」ステートメント if (this.Profile.ProfileDetail != null ) を追加しようとしましたが、それでも同じエラーが発生しました。

これは私のコードです:

private void SaveProfile()
    {


            this.Profile.ProfileDetail.FullName = txtfname.Text;
            this.Profile.ProfileDetail.IdentityCardNo = txtcardno.Text;
            this.Profile.ProfileDetail.IdentityCardColour = ddlcardcolor.SelectedValue;
            this.Profile.ProfileDetail.IdentityCardExpiryDate = DateTime.Parse(txtcardexp.Text);
            this.Profile.ProfileDetail.Race = ddlrace.SelectedValue;
            this.Profile.ProfileDetail.Religion = ddlreligion.SelectedValue;
            this.Profile.ProfileDetail.ContactInformation.Address1 = txtaddress1.Text;
            this.Profile.ProfileDetail.ContactInformation.Address2 = txtaddress2.Text;
            this.Profile.ProfileDetail.ContactInformation.Address3 = txtaddress3.Text;
            this.Profile.ProfileDetail.ContactInformation.Postcode = txtpostcode.Text;
            this.Profile.ProfileDetail.ContactInformation.District = ddldistrict.SelectedValue;
            this.Profile.ProfileDetail.ContactInformation.OfficePhone = txtphoneoffice.Text;
            this.Profile.ProfileDetail.ContactInformation.HomePhone = txtphonehome.Text;
            this.Profile.ProfileDetail.ContactInformation.MobilePhone = txtphonecell.Text;
            this.Profile.ProfileDetail.ContactInformation.Email = txtemail.Text;




        //this.Profile.ProfileDetail.FirstName = txtFirstName.Text;
        //this.Profile.ProfileDetail.LastName = txtLastName.Text;
        //this.Profile.ProfileDetail.IdentityCardNo = txtICNo.Text;
        //this.Profile.ProfileDetail.DateOfBirth = DateTime.Parse(txtDateOfBirth.Text);
        //this.Profile.ProfileDetail.Gender = (Gender)Enum.Parse(typeof(Gender), ddlGender.SelectedValue, true);
        //this.Profile.Preferences.TimeZone = ddlTimeZones.SelectedValue;
        //this.Profile.Preferences.Culture = ddlCultures.SelectedValue;

        this.Profile.Save();

        this.ResetElements();
    }
4

1 に答える 1

0

この行this.Profile.ProfileDetailは、例外をスローしている行ではない可能性があります。コードに足を踏み入れましたか?それはおそらく.SelectedValue. 値が選択されていない場合は null がスローされます。

于 2013-07-17T03:20:18.107 に答える