Update multiple rows and columns using respective ids in mssql

I extracted data from database in excel format using sql join query. I modified few … Read more Update multiple rows and columns using respective ids in mssql

I extracted data from database in excel format using sql join query. I modified few columns data in to that excelsheet. I want update modified data into database using respective row ids.
When I iterate stack:'Error: aborted is throwing. can you please suggest your right solutions.
below is my code which I tried.

sql.connect(db, async (err)=> {
  if (err)
    console.log(err);
  var request = new sql.Request();
var workbook = XLSX.readFile('2021-08-30-202129.xlsx');
var sheet_name_list = workbook.SheetNames;
var xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[1]]);
console.log(xlData);
xlData.forEach(async (item)=>{
  let returnquery = await ` UPDATE [billing] SET notes='${item.notes}' WHERE id='${item.id}'`
    request.query(returnquery, function (err, result) {
      if (err) {
        console.log(err)
      }
      else{
        console.log('result', result);
      }
      sql.close();
    }); 
  })
  }); 

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *