title: Passing Stored Procedure query result from JSonResult to Ajax
body: <p>Good Day! I'm trying to display the result of a stored procedure query into a textbox on my page. This stored procedure only returns one result which is the daily sales. I'm trying to do this passing through JSonresult so that I can pass it to an ajax in my view page. But I couldn't seem to succeed in passing it. </p>
  
  <p>I have a table named <strong>ORDER</strong> that has a <strong>ORDER_DATE</strong> &amp; <strong>NET_AMOUNT</strong> column. I need to display the sum of the net_amount for the current day. Here is my query:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>SELECT SUM(NET_AMOUNT) AS DAILY_SALES
  FROM [ORDER]
  WHERE ORDER_DATE = GETDATE()</code></pre>
  </div>
  </div>
  </p>
  
  <p>I then call this stored procedure in my controller with this Method:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>        public JsonResult GetSalesToday()
          {
              DataTable dtTable = new DataTable();
              List&lt;string&gt; lstSales = new List&lt;string&gt;();
  
  
              string strQuery = "SP_DAILY_SALES";
  
              SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
              SqlCommand cmd = new SqlCommand(strQuery, con);
              cmd.CommandType = CommandType.StoredProcedure;
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              da.Fill(dtTable);
  
  
              foreach (DataRow row in dtTable.Rows)
              {
                  lstSales.Add(row["DAILY_SALES"].ToString());
              }
  
  
              var DailySales = new
              {
                  SALESTODAY = lstSales
              };
  
  
              return Json(DailySales, JsonRequestBehavior.AllowGet);
  
          }  </code></pre>
  </div>
  </div>
  </p>
  
  <p>and then calling it to the my view with this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  $.ajax(
                         {
                             datatype: "json",
                             type: "POST",
                             url: "/Sales/GetSalesToday",
                             data: JSON,
                             success: function (data) {
                                 DailySales(data);
                             },
                             error: function () { alert("Error"); }
                         });</code></pre>
  </div>
  </div>
  </p>
  
  <p>How do I call it then to my textbox?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;div class="form-group"&gt;
                                  @Html.LabelFor("DailySales", "Sales", htmlAttributes: new { @class = "col-xs-4 col-sm-offset-1 col-sm-4" })
                                  &lt;div class="col-lg-6 col-lg-6 col-md-6 col-md-6 col-sm-6 col-sm-6 col-xs-6 col-xs-6"&gt;
                                      @Html.TextBoxFor("DailySales", new { @class = "form-control" })
                                      @Html.ValidationMessageFor("DailySales", "", new { @class = "text-danger" })
                                  &lt;/div&gt;
                              &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Where am I going wrong? Can someone help me out on this? Thanks in advance!</p>