1

当我尝试在 Quickbooks Desktop 中创建新客户时出现错误。

错误:对象引用未设置为对象的实例。

当我尝试为客户创建地址时发生错误。

 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);

就像我说的那样,当它到达第一个地址行时就会发生错误。Name、GivenName 和 FamilyName 字段有效,因此它必须与地址数组有关。我已经坚持了几天,任何帮助将不胜感激。

4

1 回答 1

3

创建一个 PhysicalAddress 对象并将其分配回 Customer Address 属性:

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 };

这同样适用于电话和电子邮件属性。

于 2013-02-06T21:50:13.290 回答