ngx-translate/http-loader

Retrieve Contents of a Recordset read from MSSQL nodejs

allabs4limp opened this issue · 2 comments

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.

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"
}
]

I ran into the same issue too, any workarounds?