2013-02-06 56 views
1

我在嘗試在Quickbooks Desktop中創建新客戶時出現錯誤。錯誤,同時嘗試使用.net DevKit 2.0創建新客戶

錯誤: 未將對象引用設置爲對象的實例。

當我嘗試爲客戶創建地址時發生錯誤。

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字段可以工作,因此它必須與地址數組有關。 我一直堅持這一兩天,任何幫助將不勝感激。

回答

3

創建PhysicalAddress對象,併爲其分配回客戶地址屬性:

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

這同樣適用於電話和電子郵件的屬性。

相關問題