Using stored procedure to display data in the datatable.

Using stored procedure to display data in the datatable.

minhalminhal Posts: 76Questions: 12Answers: 0

Hi, I am trying to use stored procedures to call data into my data table instead of just calling my table from the database. As I have certain conditions for the data to be first displayed and then exported after having the data which matches having those conditions. So it can only be achieved by using creating stored procedures. However I am uncertain how to call stored procedures in data tables.

Thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @minhal ,

    I assume you're not using Editor - if you are, this page will help.

    Otherwise, the data for DataTables is returned by an Ajax call - either under DataTables control with ajax, or externally and DataTables just initialises using the returned data. Therefore, you just need to ensure the stored procedure is callable by your server-side script, which then returns the data in the expected format,

    Cheers,

    Colin

  • minhalminhal Posts: 76Questions: 12Answers: 0

    Hi Colin,

    I am not using Editor. How can I call my stored procedure inside my ajax call? Can you please provide a example for it? I am using .net MVC5.

    Thanks

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @minhal ,

    You'll need to call a script on the server, which would then call the stored procedure to get the data in the required format.

    Cheers,

    Colin

  • minhalminhal Posts: 76Questions: 12Answers: 0

    @colin ,

    "ajax": {
    "url": "/StructuredImportTgts/GetData",
    "type": "GET",
    "datatype": "json"
    },

    This is how I am getting my ajax call. So how can I call it in server side?

  • minhalminhal Posts: 76Questions: 12Answers: 0

    @colin ,

    Say if my stored procedure is called 'usp_GetBomApplicationImportTGT' and my controller name is StructuredImportTgts. How am I supposed to call a script from the server?

    Thanks

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    That's really outside the scope of the support we can provide I'm afraid. You are asking how to use Ajax with .NET - Stackoverflow would be much better suited for that kind of question.

    In short you need to have an HTTP route for your controller (so it can be accessed by a browsers call) and have your controller query your database's stored procedure.

    Allan

  • minhalminhal Posts: 76Questions: 12Answers: 0

    Hi @allan ,

    Thanks for your reply. I would ask different platform to get the answer for this question.

This discussion has been closed.