0

I want to insert and update data into database on button click but when I fill all fields and start debugging and when dubugger is on buyer code this error is occurred "object reference not set to an instance of an object". Kindly help me.......

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 回答