derrickh13
derrickh13

Reputation: 13

error while trying to create a new customer using .net DevKit 2.0

I am getting an error when I try to create a new customer in Quickbooks Desktop.

The error: Object reference not set to an instance of an object.

The error occurs when I try to create the address for the customer.

 Customer qbdCustomer = new Customer();
                qbdCustomer.Name = txtCompany.Text;
                qbdCustomer.GivenName = txtFName.Text;
                qbdCustomer.FamilyName = txtLName.Text;                    
                qbdCustomer.Address[0].Line1 = txtAddress.Text;
                qbdCustomer.Address[0].Line2 = txtAddress2.Text;
                qbdCustomer.Address[0].City = txtCity.Text;
                qbdCustomer.Address[0].CountrySubDivisionCode = drpState.SelectedItem.Value;
                qbdCustomer.Address[0].PostalCode = txtZip.Text;
                qbdCustomer.Phone[0].FreeFormNumber = txtPhone.Text;
                qbdCustomer.Email[0].Address = txtEmail.Text;
                Customer customerAdded = (new DataServices(context)).Add(qbdCustomer);

Like I said the error occurs when it gets to the first address line. The Name, GivenName, and FamilyName fields work so it has to be something to do with the array for the address. I have been stuck on this for a couple days, any help would be greatly appreciated.

Upvotes: 1

Views: 110

Answers (1)

Peter Lavelle
Peter Lavelle

Reputation: 1484

Create a PhysicalAddress object and assign it back to the Customer Address property:

Intuit.Ipp.Data.Qbd.PhysicalAddress customerAddress = new Intuit.Ipp.Data.Qbd.PhysicalAddress();
customerAddress.Line1 = txtAddress.Text;
customerAddress.Line2 = txtAddress2.Text;
customerAddress.City = txtCity.Text;
customerAddress.CountrySubDivisionCode = drpState.SelectedItem.Value;
customerAddress.PostalCode = txtZip.Text;
qbdCustomer.Address = new Intuit.Ipp.Data.Qbd.PhysicalAddress[]{ customerAddress };

The same applies to the Phone and Email properties.

Upvotes: 3

Related Questions