0

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();
        }
    }
});
2
  • How this is a reactjs question? Commented Dec 14, 2023 at 10:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Dec 17, 2023 at 12:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.