title: AJAX Line Chart in Asp.Net
body: <p>I am having some problem when trying to set up an AJAX line chart in asp.net. What I am trying to do is I select a category from drop down list, then the line chart will display the sum of products sent out in every month by each category. Here is the code in presentation layer:</p>
  
  <pre><code>protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
  {
      string categoryName = ddlCategory.SelectedItem.ToString();
      string deliveryDate = "";
      decimal[] totalQuantity;
  
      List&lt;ProductPacking&gt; catSumList = new List&lt;ProductPacking&gt;();
      for (int count = 0; count &lt; catSumList.Count; count++)
      {
          deliveryDate = catSumList[count].deliveryDate;
          totalQuantity = Convert.ToDecimal(catSumList[count].productQuantity);
      }
      lcCategory.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = totalQuantity });
      lcCategory.CategoriesAxis = string.Join(",", deliveryDate);
      lcCategory.ChartTitle = string.Format("", deliveryDate);
      lcCategory.Visible = true;
  }
  </code></pre>
  
  <p>And the code in Business Logic Layer:</p>
  
  <pre><code>public List&lt;ProductPacking&gt; getSumCategoryByMonth(string categoryName)
  {
      List&lt;ProductPacking&gt; ft = new List&lt;ProductPacking&gt;();
      ft = prodPack.getSumCategoryByMonth(categoryName);
      return ft;
  }
  </code></pre>
  
  <p>And the code in Data Access Layer:</p>
  
  <pre><code>public List&lt;ProductPacking&gt; getSumCategoryByMonth(string categoryName)
  {
      List&lt;ProductPacking&gt; ft = new List&lt;ProductPacking&gt;();
  
      using (var connection = new SqlConnection(FoodBankDB.connectionString))
      {
          SqlCommand command = new SqlCommand("SELECT SUM(Convert(INT, ddi.productQuantity)) AS totalQuantity, pc.categoryName, d.deliveryDate FROM dbo.DistributionDistributedItems ddi " +
              " INNER JOIN dbo.ProductVariants pv ON ddi.productVariant = pv.id " +
              " INNER JOIN dbo.Products p ON pv.product = p.id " +
              " INNER JOIN dbo.ProductCategories pc ON p.productCategory = pc.id " +
              " INNER JOIN dbo.Distributions d ON ddi.distribution = d.id " +
              " WHERE categoryName = '" + categoryName + "'" + 
              " GROUP BY pc.categoryName, d.deliveryDate", connection);
          connection.Open();
          using (var dr = command.ExecuteReader())
          {
              while (dr.Read())
              {
                  ft.Add(new ProductPacking(Convert.ToInt32(dr["totalQuantity"].ToString()), dr["deliveryDate"].ToString()));
              }
          }
      }
      return ft;
  }
  </code></pre>
  
  <p>However, there is an error at the presentation layer around the </p>
  
  <pre><code>totalQuantity = Convert.ToDecimal(catSumList[count].productQuantity);
  </code></pre>
  
  <p>line. The error message is Cannot implicit convert type decimal to decimal[]. I referred from this website: <a href="http://www.aspsnippets.com/Articles/ASPNet-AJAX-Line-Chart-Control-Populate-from-Database-example.aspx" rel="nofollow">Line Chart In Asp.Net</a></p>
  
  <p>I wonder how to fix this according to my situation. Thanks in advance.</p>