0

I have used pyodbc.executemany to insert items in database tables. I am trying to update multiple rows using pyodbc.executemany and I keep getting errors. Is it possible to use pyodbc.executemany for updating multiple rows?

Here is my code:

import pyodbc
import os
listTest=[('okAa','a'),('OKBb','b')]

queryToTest="UPDATE AllTrasactions2 SET [Barcode]=? WHERE [Location]=?"
strForDB = os.getcwd() + '\DBINFO.txt'
openDBFile = open(strForDB, 'r')
currentDirForDB = openDBFile.read()
dbPath = currentDirForDB

con = pyodbc.connect(dbPath)
cur = con.cursor()
cur.executemany(queryToTest,listTest)
con.commit()

This is my error:

Traceback (most recent call last):
  File "C:/Users/Test/test.py", line 13, in <module>
    cur.executemany(queryToTest,listTest)
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'AllTrasactions2'. (208) (SQLExecDirectW); [42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)")

Vik
  • 137
  • 1
  • 8

0 Answers0