Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Retrieve Contents of a Recordset read from MSSQL nodejs #52

Open
allabs4limp opened this issue Jul 6, 2018 · 2 comments
Open

Retrieve Contents of a Recordset read from MSSQL nodejs #52

allabs4limp opened this issue Jul 6, 2018 · 2 comments

Comments

@allabs4limp
Copy link

I have a get API that queries a database and returns details abut the parameter supplied. Below is the code the returns a recordset saved in result variable


router.get('/:examno', (req, res) => { 
    var request = new sql.Request();
    // query to the database and get the records
    request.input('examno', sql.NVARCHAR, req.params.examno);
    request.execute('dbo.spGetCandidatesDetails', function (err, result) {    
        if (err) console.log('Error in retrieving Candidate : ' + JSON.stringify(err, undefined, 2));


      // send records as a response
   res.send(result);   
    });
});

I have a get API that queries a database and returns details abut the parameter supplied. Below is the code the returns a recordset saved in result variable

router.get('/:examno', (req, res) => {
var request = new sql.Request();
// query to the database and get the records
request.input('examno', sql.NVARCHAR, req.params.examno);
request.execute('dbo.spGetCandidatesDetails', function (err, result) {
if (err) console.log('Error in retrieving Candidate : ' + JSON.stringify(err, undefined, 2));

  // send records as a response

res.send(result);
});
});
The recordset returns this in JSON

"recordsets": [
        [
            {
                "CandidateID": 1,
                "CandidateExamNo": "12345",
                "CandidateSubjectCombination": "1:2:3:4",
                "CandidateToken": "7e7b3055-0c5b-47b2-81ae-0815cef16e9d",
                "CandidateName": "Testing Testing Microphone"
            }
        ]
    ],
    "recordset": [
        {
            "CandidateID": 1,
            "CandidateExamNo": "12345",
            "CandidateSubjectCombination": "1:2:3:4",
            "CandidateToken": "7e7b3055-0c5b-47b2-81ae-0815cef16e9d",
            "CandidateName": "Testing Testing Microphone"
        }
    ],
    "output": {},
    "rowsAffected": [],
    "returnValue": 0

Now, i want to read the contents of the recordset into a variable to be able to have access to each of the field names in the recordset.

Thanks.

@zexcon
Copy link

zexcon commented Apr 24, 2020

allabs4limp if I understand the ask correctly. I believe you would want something like this result['recordset'] this would result in the array below.
[
{
"CandidateID": 1,
"CandidateExamNo": "12345",
"CandidateSubjectCombination": "1:2:3:4",
"CandidateToken": "7e7b3055-0c5b-47b2-81ae-0815cef16e9d",
"CandidateName": "Testing Testing Microphone"
}
]

@mudouasenha
Copy link

I ran into the same issue too, any workarounds?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants