title: Data is Null in my case in my List.Add
body: <p>I am getting an error from following code, which has written for show table data</p>
  
  <blockquote>
    <p>Data is Null. This method or property cannot be called on Null values.</p>
  </blockquote>
  
  <p>So here is my code so that you can help me investigate it.</p>
  
  <pre><code>public static List&lt;NomsPRRequest&gt; LoadPRfromDB_withParams(DateTime from, DateTime to, string EntityID,
          string DepartmentID)
      {
          string sScript = m_sReport + ((EntityID == "") ? "" : " AND d.[EntityID]=" + EntityID) + ((DepartmentID == "") ? "" : " AND d.[DepartmentID]=" + DepartmentID)
              + " and [RequestDate] between '" + from.ToString("yyyy-MM-dd HH:mm:ss") + "' and '" + to.ToString("yyyy-MM-dd HH:mm:ss") + "'";
          Dictionary&lt;long, NomsPRRequest&gt; data = new Dictionary&lt;long, NomsPRRequest&gt;();
          long key;
          double dAmount;
          using (SqlConnection con = new SqlConnection(m_sConnectionString))
          {
              con.Open();
              using (SqlCommand command = new SqlCommand(sScript, con))
              {
                  SqlDataReader reader = command.ExecuteReader();
                  while (reader.Read())
                  {
                      key = reader.GetInt64(0);
                      if (!data.ContainsKey(key))
                      {
                          data.Add(key, new NomsPRRequest()
                          {
                              RequestID = key,
                              RequestDate = reader.GetDateTime(1),
                              PARNumber = reader.GetString(2),
                              DepartmentName = reader.GetString(10),
                              DepartmentID = reader.GetInt64(11),
                              StatusID = reader.GetInt64(3),
                              FullName = reader.GetString(7),
                              InboxLearUID = reader.GetString(12),
                              ProgramName = reader.GetString(14),
                              ItemList = new List&lt;NomsPRItem&gt;(),
                              TotalAmount = 0.0
                          });
                      }
                      dAmount = (double)reader.GetDecimal(21) * (double)reader.GetDecimal(22);
                      data[key].TotalAmount += dAmount;
                      ****data[key].ItemList.Add(new NomsPRItem()****
                      {
                          RequestID = key,
                          PartDesc = reader.GetString(17),
                          PartNumber = reader.GetString(23),
                          SupplierID = reader.GetString(18),
                          FullName = reader.GetString(7),
                          AccountType = reader.GetString(19),
                          CurrName = reader.GetString(20),
                          PartQuantity = (double)reader.GetDecimal(21),
                          PiecePrice = (double)reader.GetDecimal(22),
                          Amount = dAmount
                      });
                  }
              }
          }
  
          return data.Values.ToList();
      }
  </code></pre>
  
  <p>I get error on this part </p>
  
  <blockquote>
    <p><strong>data[key].ItemList.Add(new NomsPRItem()</strong></p>
  </blockquote>
  
  <p>Here is my view ..</p>
  
  <pre><code>  &lt;table data-ng-show="models != null" class="table table-striped table-bordered table-hover"
                  id="PRTable" &gt;
  
                  &lt;tr class="titlerow"&gt;
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='RequestDate'; reverse = !reverse"&gt;PR Date &lt;span
                              data-ng-show="sorting == 'RequestDate'"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='RequestID '; reverse = !reverse"&gt;PR # &lt;span data-ng-show="sorting == 'RequestID '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='PARNumber '; reverse = !reverse"&gt;PAR # &lt;span
                              data-ng-show="sorting == 'PARNumber '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='ProgramName '; reverse = !reverse"&gt;Program &lt;span
                              data-ng-show="sorting == 'ProgramName '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='FullName '; reverse = !reverse"&gt;Requestor &lt;span
                              data-ng-show="sorting == 'FullName '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='DepartmentName '; reverse = !reverse"&gt;Department &lt;span
                              data-ng-show="sorting == 'FullName '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='PONo'; reverse = !reverse"&gt;PO # 
                          &lt;/a&gt;
                      &lt;/th&gt;
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='StatusID '; reverse = !reverse"&gt;PRStatus&lt;span
                              data-ng-show="sorting == 'StatusID '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='Amount '; reverse = !reverse"&gt;Total Amount&lt;span
                              data-ng-show="sorting == 'Amount '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
  
                      &lt;th&gt;
                          &lt;a href="#" data-ng-click="sorting='InboxLearUID '; reverse = !reverse"&gt;Last Action&lt;span
                              data-ng-show="sorting == 'InboxLearUID '"&gt;&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/th&gt;
                  &lt;/tr&gt;
  
  
                  &lt;tr data-ng-repeat="model in models  | orderBy: sorting:reverse | filter : filterAllColumns | filter : filterOptions "&gt;
  
                      &lt;td&gt;{{jsonDatetotext(model.RequestDate) | date:'MM/dd/yyyy'}}&lt;/td&gt;
                      &lt;td&gt;
                          &lt;a href="#" data-toggle="modal" data-target="#basicModalContent" data-ng-click="getSelectedPR(model)"&gt;{{model.RequestID}}
                          &lt;/a&gt;
                      &lt;/td&gt;
                      &lt;td&gt;{{model.PARNumber }}&lt;/td&gt;
                      &lt;td&gt;{{model.ProgramName }}&lt;/td&gt;
                      &lt;td&gt;{{model.FullName }}&lt;/td&gt;
                      &lt;td&gt;{{model.DepartmentName | uppercase}}&lt;/td&gt;
                      &lt;td&gt;{{model.PONo}}&lt;/td&gt;
                      &lt;td&gt;{{StatusList[model.StatusID] | uppercase}}&lt;/td&gt;
                      &lt;td class="totalAmount"&gt;&lt;span class="pull-right"&gt;{{model.TotalAmount | number:2}}&lt;/span&gt;
                      &lt;/td&gt;
                      &lt;td&gt;{{model.InboxLearUID | lowercase}}&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
          &lt;!-- /.Modal Na ni --&gt;
  
          &lt;div class="modal fade" id="basicModalContent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
              aria-hidden="true"&gt;
              &lt;div class="modal-dialog"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
  
                          &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-body" id="exportablePRItems"&gt;
                          &lt;div class="table-responsive"&gt;
                              &lt;table class="table table-striped table-bordered table-hover" id="dataTables-example"&gt;
                                  &lt;thead&gt;
                                      &lt;tr&gt;
  
                                          &lt;th&gt;Item Code
                                          &lt;/th&gt;
                                          &lt;th&gt;Item Description
                                          &lt;/th&gt;
                                          &lt;th&gt;Supplier 
                                          &lt;/th&gt;
                                          &lt;th&gt;Account
                                          &lt;/th&gt;
                                          &lt;th&gt;Currency
                                          &lt;/th&gt;
                                          &lt;th&gt;Amount
                                          &lt;/th&gt;
                                          &lt;th&gt;(USD) Amount
                                          &lt;/th&gt;
                                      &lt;/tr&gt;
                                  &lt;/thead&gt;
  
                                  &lt;tbody data-ng-repeat="selectedPR in selectedModal.ItemList"&gt;
  
                                      &lt;tr&gt;
                                          &lt;td&gt;{{selectedPR.PartNumber}}&lt;/td&gt;
                                          &lt;td&gt;{{selectedPR.PartDesc}}&lt;/td&gt;
                                          &lt;td&gt;{{selectedPR.SupplierID }}&lt;/td&gt;
                                          &lt;td&gt;{{selectedPR.AccountType}}&lt;/td&gt;
                                          &lt;td&gt;{{selectedPR.CurrName }}&lt;/td&gt;
                                          &lt;td data-ng-model="amount" class="amount"&gt;{{selectedPR.Amount | number:2}}&lt;/td&gt;
                                          &lt;td&gt;{{selectedPR.AmountUSD}}&lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/tbody&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;span class="pull-right"&gt;&lt;i class="glyphicon glyphicon-plus-sign"&gt;&lt;/i&gt;&lt;/span&gt;&lt;/td&gt;
                                      &lt;td colspan="3"&gt;&lt;b&gt;{{selectedModal.RequestID}}&lt;/b&gt; &lt;/td&gt;
                                      &lt;td colspan="1"&gt;&lt;b&gt;Total :  &lt;/b&gt;&lt;/td&gt;
                                      &lt;td colspan="2"&gt;{{selectedModal.ItemList | sumbykey : 'Amount' | number:2}}&lt;/td&gt;
                                  &lt;/tr&gt;
  
                              &lt;/table&gt;
  
                          &lt;/div&gt;
                          &lt;footer&gt;
                              &lt;br /&gt;
                              &lt;button data-ng-click="exportDataItems()" class="btn btn-warning"&gt;&lt;i class="glyphicon glyphicon-export"&gt;&lt;/i&gt;Export Item &lt;/button&gt;
                          &lt;/footer&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-footer"&gt;
  
                          &lt;button id="btnModalCancel" type="button" class="btn btn-default" data-dismiss="modal"&gt;
                              Close&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Can anyone please help me to investigate this codes so that I could proceed to my next steps ? </p>