0

ボタンのクリックでデータベースにデータを挿入して更新したいのですが、すべてのフィールドに入力してデバッグを開始すると、ダバガーがバイヤーコードにあるときに、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」というエラーが発生します。助けてください........

protected void btnSaveChanges_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(ViewState["BuyerId"]) > 0)
        {
            oBuyer = new Buyer();
            //Fill object with Text box values
            oBuyer.BuyerId = Convert.ToInt32(ViewState["BuyerId"]);
            oBuyer.BuyerCode = txtBuyerCode.Text;
            oBuyer.SunCode = txtSunCode.Text;
            oBuyer.BuyerName = txtBuyerName.Text;
            oBuyer.BuyerAddress1 = txtBuyerAddress1.Text;
            oBuyer.BuyerAddress2 = txtBuyerAddress2.Text;
            oBuyer.BuyerAddress3 = txtBuyerAddress3.Text;
            oBuyer.BuyerAddress4 = txtBuyerAddress4.Text;
            oBuyer.BuyerPostCode = txtBuyerPostcode.Text;
            oBuyer.BuyerPhone = txtBuyerPhone.Text;
            oBuyer.BuyerFax = txtBuyerFax.Text;
            oBuyer.BuyerEmail = txtBuyerMail.Text;
            oBuyer.PfaCode = txtBuyerPFACode.Text;
            oBuyer.Guarantee = Convert.ToDecimal(txtBuyerGuarantee.Text);
            oBuyer.DefaultDestination = ddlBuyerDefaultDestination.SelectedValue;
            oBuyer.HbaLevy = chkHBALeavy.Checked;
            oBuyer.SfiaWhite = chkSFIAPelagic.Checked;
            oBuyer.SfiaPelagic = chkSFIAPelagic.Checked;
            oBuyer.MarketBox = txtBuyerMarketBox.Text;
            oBuyer.Comments = txtComments.Text;
            oBuyer.BuyerRegistrationNo = txtBuyerRigistrationNo.Text;

        }
        else
        {
            //Fill object with Text box values
            oBuyer.BuyerCode = txtBuyerCode.Text;
            oBuyer.SunCode = txtSunCode.Text;
            oBuyer.BuyerName = txtBuyerName.Text;
            oBuyer.BuyerAddress1 = txtBuyerAddress1.Text;
            oBuyer.BuyerAddress2 = txtBuyerAddress2.Text;
            oBuyer.BuyerAddress3 = txtBuyerAddress3.Text;
            oBuyer.BuyerAddress4 = txtBuyerAddress4.Text;
            oBuyer.BuyerPostCode = txtBuyerPostcode.Text;
            oBuyer.BuyerPhone = txtBuyerPhone.Text;
            oBuyer.BuyerFax = txtBuyerFax.Text;
            oBuyer.BuyerEmail = txtBuyerMail.Text;
            oBuyer.PfaCode = txtBuyerPFACode.Text;
            oBuyer.Guarantee = Convert.ToDecimal(txtBuyerGuarantee.Text);
            oBuyer.DefaultDestination = ddlBuyerDefaultDestination.SelectedValue;
            oBuyer.HbaLevy = chkHBALeavy.Checked;
            oBuyer.SfiaWhite = chkSFIAPelagic.Checked;
            oBuyer.SfiaPelagic = chkSFIAPelagic.Checked;
            oBuyer.MarketBox = txtBuyerMarketBox.Text;
            oBuyer.Comments = txtComments.Text;
            oBuyer.BuyerRegistrationNo = txtBuyerRigistrationNo.Text;
        }

        //enter into nSYScatch6 service
        bool saveBuyer = nSYSCatch6ServiceInitiator.SaveBuyer(oBuyer);
        if (saveBuyer)
        {
        }
        Response.Redirect(Request.RawUrl);
    }
4

1 に答える 1

1

ブランチoBuyer = new Buyer();にがありません。else

于 2013-04-12T07:13:22.527 に答える