次のコードがあります。
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();
}
}
}
私の問題は、2 人の人物が同じ名前でクイックブックに入力する必要がある場合があることですが、このコードを複数回実行すると (「テスト顧客 1」を複数回追加しようとすると)、2 回目は私は行にエラーをスローします:
custID = customerRet.ListID.GetValue();
言います:
Object reference not set to an instance of an object
例外をスローせずに、QBFC を使用して重複した顧客を QB に追加する方法はありますか?