The JSON output is not returning the correct values from the stored procedure and is instead displaying -1

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);
    }
}

Answer №1

After making some adjustments to the Controller code, I am now seeing the results that I was aiming for. Surprisingly, I didn't really change much.

[Authorize]
public JsonResult fetchMemberSummary(string memberID, string startDate, string endDate)
{
    try
    {
        using (sqlConnection)
        {
            DateTime start = Convert.ToDateTime(startDate);
            DateTime end = Convert.ToDateTime(endDate);

            var summary = sqlConnection.Query("get_summary_memberStatement", new {
                memberID,
                start,
                end
            }, commandType: CommandType.StoredProcedure);
            
            return Json(summary, JsonRequestBehavior.AllowGet);

        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting problem in Vercel with Next.js 13 application - encountering "Module not found" error

Encountering a deployment issue with my Next.js 13 application on Vercel. I recently implemented the Parallel Routes feature of Next in my codebase. While pushing the changes to create a new pull request on GitHub, the branch's deployment on Vercel is ...

What is preventing me from displaying my paragraph?

I have some content that I want to show a paragraph with the class paragraphtoggle when clicked, but it's not working as expected. Here is what I have tried: https://example.com/jsfiddle HTML <div class="enzimskiprogramindex herbaprogramindex he ...

Tips for retrieving a value from a callback function?

How do I return a value from a callback function? The following code snippet is what I have: function storeData(data) { const id = "5f354b7470e79f7e5b6feb25"; const body = { name: "john doe" }; bucket.insert(id, body, (error, r ...

What is the best way to send information from server-side code to an EJS template?

I am facing an issue with retrieving data from my simple server for an ejs template. While I can successfully get the data through the URL in my browser, I am struggling to pass it to the template. This is my data retrieval method: app.get('/some&ap ...

Attempting to divide a sentence based on the specified output criteria below

I am trying to split a sentence into individual words and create a new array. If the word is found in another array, I want to replace it with an empty string and add space where necessary. The desired output should look like this: Arr=["I want to ea ...

What is the best way to navigate to a component that has been imported in Vue.js?

I have knowledge of Vue's scrollBehavior function, but I am struggling to integrate it with my existing code. On my Index page, I have sections composed of imported Vue components like this: <template> <div class="Container"> <Ab ...

Issues arise when trying to use JQuery in conjunction with JSON data

I've been working on a project that involves creating a dynamic dropdown list, but I've run into an issue with jQuery and JSON. This is my first time working with JSON, so I'm still getting the hang of it. Despite googling for solutions, I h ...

The dropdown menu disappears when I hover over the tab, making it impossible for me to navigate it in the react app

My navigation component includes a Games tab with a dropdown menu that appears when you hover over it. However, I'm facing an issue where the dropdown menu closes before the user can transition from hovering over the games tab to the actual dropdown m ...

What methods can I use to prevent caching of XMLHttpRequest requests without relying on jQuery?

I am currently working on a web application that refreshes a table every minute from an XML file. However, I have noticed that when I make edits to the content of the XML file, I see a "304 Not Modified" message in the script log when trying to retrieve th ...

Tips for obtaining dynamic CSV downloads in asp.net

ENV: Asp.Net Vb / Visual Studio 2010 / .Net 4 IIS Express and IIS 6 There seems to be an issue with my download.aspx page where the downloaded file always has the name of the page instead of the specified file name. I have tried using Content-Disposition ...

Storing JSON data in an SQLite database involves creating a table with a

I'm having trouble figuring out how to save data in 'JSON' format into my sqlite database for a Rails application. I've looked into various methods, but so far haven't found any promising solutions. Can anyone provide guidance on h ...

Does jQuery have any pre-built validation for LinkedIn profile URLs?

After researching, I discovered that there are suggestions to use regex or a custom function for validating LinkedIn profile URLs in jQuery. I wonder if there is a built-in function available, similar to email validation methods? For instance, consider t ...

Converting a JavaScript string containing an `import` statement into a browser-compatible function

Can my vue application transform the given string into a callable function? const test = 'import { pi } from "MathPie"; function test() { console.log(pi); } export default test;' The desired output format is: import { pi } from "M ...

Adjusting HTML/JSX in Response to Screen Size

I want to update the text inside a <p> tag depending on the screen size. There are two approaches that come to mind: Include the text like this: <p> <span className="one">text one</span> <span className="two ...

Executing several tasks simultaneously with respect to one another, yet in synchronization with the overall program flow

So, I have an async function with a try block that looks something like this: async function functionName() { try { await function1() // all these functions are async await function2() await function3() // more awaits below } catch(err) ...

Every time I switch tabs in Material UI, React rebuilds my component

I integrated a Material UI Tabs component into my application, following a similar approach to the one showcased in their Simple Tabs demo. However, I have noticed that the components within each tab — specifically those defined in the render method ...

The function .remove() fails to remove a text node in Internet Explorer

Check out the code here: http://jsfiddle.net/6nN7G/ Utilizing a shopify app for star reviews that generates div.text - my aim is to eliminate the text indicating the number of reviews such as "19 reviews" and "3 reviews" from the HTML. This action is perf ...

Switch up primary and secondary color schemes with the Material UI Theme swap

Exploring Material UI themes for React JS is a new venture for me. I am facing a scenario where I need to dynamically change the theme colors (Primary & Secondary) based on a selected type from a dropdown menu. Similar to the color customization options av ...

Troubleshooting ng-class functionality in AngularJS

I am attempting to utilize AngularJS in order to change the class name of a div element. Despite following the guidance provided in this answer, I am encountering difficulties as the class name is not updating in my view. Below is the code from my view: ...

Tips for shifting a fabricjs element generated within a nextjs useState hook?

I encountered an issue where creating a fabric canvas in a useEffect() function prevents me from moving the added images. However, if I create the canvas elsewhere (even though it may be subject to useState asynchrony issues), I am able to move the image ...