为什么ExpenseLineRetList返回null

时间:2014-03-31 05:27:43

标签: c# quickbooks qbfc

我看到了this link,我注意到我们遇到了同样的问题,他的问题仍然没有回答。

这是一个问题。

public class ServiceSel
    {
        public void GetCheqe()
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager rp = null;

        try
        {
            rp = new QBSessionManager();
            IMsgSetRequest requestMsgSet = rp.CreateMsgSetRequest("US", 8, 0);
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            rp.OpenConnection("Database Path File QuickBooks", "QuickBooks Integration Demo");
            connectionOpen = true;
            rp.BeginSession("", ENOpenMode.omDontCare);
            sessionBegun = true;

            ICheckQuery checkQuery = requestMsgSet.AppendCheckQueryRq();
            IMsgSetResponse msgSetRs = rp.DoRequests(requestMsgSet);
            IResponse response = msgSetRs.ResponseList.GetAt(0);
            ICheckRetList checkRetList = (ICheckRetList)response.Detail;

            if (checkRetList != null)
            {
                for (int i = 0; i < checkRetList.Count; i++)
                {
                        ICheckRet checkRet = checkRetList.GetAt(i);
                        //Bank Account On top 
                        string TxnID = checkRet.TxnID.GetValue().ToString();       //Data correct
                        string TxnNumber = checkRet.TxnNumber.GetValue().ToString();   //Data correct
                        string Account = checkRet.AccountRef.FullName.GetValue();   //Data correct
                        string Amount = checkRet.Amount.GetValue().ToString();   //Data correct

                         if (checkRet.ExpenseLineRetList != null)
                         {
                                 Error checkRet.Expense Show null Data But in quickbooks have many data expense in calendar 

                         }      
                }
            }
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message, "Error");
        }
        finally
        {
            if (sessionBegun)
            {
                rp.EndSession();
            }
            if (connectionOpen)
            {
                rp.CloseConnection();
            }
        }

    }

为什么ExpenseLineRetList为空?

1 个答案:

答案 0 :(得分:2)

检查请求不会包含检查的详细信息行,除非您将其包含在查询中。通过添加IncludeLineItems设置,您可以访问支票的费用或项目清单(支票可以包含费用行,项目行或两者)。您需要更改以包含以下内容:

ICheckQuery checkQuery = requestMsgSet.AppendCheckQueryRq();
checkQuery.IncludeLineItems.SetValue(true);
IMsgSetResponse msgSetRs = rp.DoRequests(requestMsgSet);

我还建议您在尝试获取响应详细信息之前检查响应代码,以便更好地处理错误:

IResponse response = msgSetRs.ResponseList.GetAt(0);
if(response.StatusCode != 0)
{
    // There was an error. response.StatusCode has the error number
    // response.StatusMessage has the error description.
}
else
{        
    ICheckRetList checkRetList = (ICheckRetList)response.Detail;
    .
    .
    .
}