I have a page, I need to submit the data of that page into a SQL Server database table. There is already written the queries in the procedure. I need to use those queries in my server. How can I use that procedure?
app.get('/salesman_registration', async (req, res) => {
let pool;
try {
pool = await sql.connect(conStr);
// Use the stored procedure with the specified statement type
const result = await pool
.request()
.input('StatementType', sql.NVarChar(50), 'insert') // Specify the statement type here
.execute(`'exec Sp_LedgerRegistration , @ledcode=0,@ledname=@name,@parent=@res,@add1=@Address1 ,@add2=@address2 ,@add3=@address3 ,@statementType = Insert'`);
const latestSlNo = result.recordset[0].latestSlNo || 0;
res.status(200).send({ slNo: latestSlNo });
} catch (err) {
console.error(err);
res.status(500).send('Error retrieving latest slNo from the database');
} finally {
if (pool) {
pool.close();
}
}
});
reactjs
question?