检索从nodejs和mssql包读取的记录集的内容

时间:2018-07-06 07:56:46

标签: node.js angular

我有一个get API,可以查询数据库并返回有关所提供参数的详细信息。下面是返回保存在结果变量中的记录集的代码

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

记录集以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

现在,我想将记录集的内容读入一个变量中,以便能够访问记录集中的每个字段名称。

谢谢。

0 个答案:

没有答案