In this code snippet, the view is set up to display results using an Ajax form. However, when the results are generated, a -1
value is returned. Interestingly, executing the stored procedure in SQL Server returns the desired column values.
<script type="text/javascript">
function generateStatement() {
var member_number = $('#member').val();
var firstDate = $('#start_date').val();
var secondDate = $('#end_date').val();
const url = '/memberbalances/getSummary_statement';
$.getJSON(url, { member_number, firstDate, secondDate},function (data) {
$.each(data, function (key, entry) {
console.log(entry);
})
})
}
</script>
The controller code involves using Dapper ORM for mapping queries to the database. Upon clicking the button to generate results, -1
is returned instead of the expected column values from the SQL server stored procedure.
[Authorize]
public JsonResult getSummary_statement(string member_number,string firstDate,string secondDate)
{
try
{
using (sqlConnection)
{
DateTime startDate= Convert.ToDateTime(firstDate);
DateTime endDate = Convert.ToDateTime(secondDate);
var summary_statement = sqlConnection.Execute("get_summary_memberStatement",
new
{
member_number,startDate,endDate
},commandType:CommandType.StoredProcedure);
return Json(summary_statement,JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}