我已经在我的Node API后端实现了简单的SQL调用。我在node-mssql中使用存储过程。正在运行的简单代码如下所示:
//pull in the connection string
sql.connect(connection).then(pool => {
// Stored procedure
return pool.request()
.input('email', sql.VarChar(120), extraColon)
.execute('Login');
}).then(result => {
res.send(result);
}).catch(err => {
// ... error checks这在几次不同的调用中都能正常工作,没有问题。我开始需要在最新的调用中传递多个参数,并认为这也很容易:
//pull in the connection string
sql.connect(connection).then(pool => {
// Stored procedure
return pool.request()
.input(('email', sql.VarChar(120), extraColon),
('password', sql.VarChar(120), extraColon1))
.execute('Login');
}).then(result => {
res.send(result);
}).catch(err => {
// ... error checks我添加了2,但它不能识别我传递的内容。我所寻找的不是比这更大不同的东西,只是将多个参数传递到我的存储过程中的简单方法。我将一个有效负载从React传递到我的Node JS后端,将其拆分成我需要的部分,然后将它们作为单独的参数传递。感谢你在这方面的帮助!
发布于 2021-02-12 10:57:01
我认为您只需为每个参数添加以.input开头的另一行,如下所示:
sql.connect(connection).then(pool => {
// Stored procedure
return pool.request()
.input('email', sql.VarChar(120), extraColon)
.input('password', sql.VarChar(120), extraColon1)
.execute('Login');
}).then(result => {
res.send(result);
}).catch(err => {
// ... error checks对于更多的参数,这对我也是有效的。
https://stackoverflow.com/questions/66164863
复制相似问题