无法使用QBFC向Quickbooks添加重复客户

本文关键字:添加 客户 Quickbooks QBFC | 更新日期: 2023-09-27 18:09:39

我有以下代码:

public void addCustomer()
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;
            try
            {
                //Create sessions manager object
                sessionManager = new QBSessionManager();
                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                //Connect to quickbooks and begin a session
                sessionManager.OpenConnection("", "CSW QB Interface");
                connectionOpen = true;
                sessionManager.BeginSession(@"C:'Users'Public'Documents'Intuit'QuickBooks'Company Files'Super Legit Industries.qbw", ENOpenMode.omDontCare);
                sessionBegun = true;
                ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
                customerAddRq.Name.SetValue("Test Customer 1");
                //Send the request and get the response from quickbooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRet customerRet = (ICustomerRet)response.Detail;
                //Console.WriteLine(response.Detail.ToString());
                custID = customerRet.ListID.GetValue();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                //End the session and close the connection to quickbooks
                if(sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if(connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
        }

我的问题是,可能会有两个人有相同的名字,需要输入到quickbooks中,但是如果我不止一次地运行这段代码(试图不止一次地添加"Test Customer 1"),第二次我就会抛出一个错误:

custID = customerRet.ListID.GetValue();

说:

Object reference not set to an instance of an object

是否有任何方法可以使用QBFC将重复客户添加到QB中而不会抛出异常?

无法使用QBFC向Quickbooks添加重复客户

我的问题是,可能会有两个人有相同的名字,需要输入quickbooks,

QuickBooks本身不支持有两个同名的客户

你遇到的不是QBFC的限制,或者SDK,或者任何东西——这就是QuickBooks的工作原理。你不能有重复的