I've been stuck in this problem for a long time, i hope somebody could enlighten me. I have a sql database i would like to update. Here are some pieces of the code. I extracted data from sql to Python, then apply function hex_to_string & slicing bin and I plan to update the SQL database. I don't have any ID in the database, but I have the DATETIME which differentiates the entry.
query = """ select P from Table """
cnxn = pyodbc.connect(conn_str)
cnxn.add_output_converter(pyodbc.SQL_VARBINARY, hexToString)
cursor: object = cnxn.cursor()
cursor.execute(query)
dtbs= cursor.fetchall()
row_list=[]
ln = len(dtbs)
cursor.execute(query)
for i in range(ln):
row=cursor.fetchval()
result=slicing_bin(row)
result_float = [float("{0:.2f}".format(i)) for i in result]
row_list.append(result_float)
crsr = cnxn.cursor()
crsr.execute(query)
aList = [item[0] for item in crsr.fetchall()]
for aValue in aList:
crsr.execute("""UPDATE Table SET P=? WHERE DATETIME=?""", (row_list, aValue))
crsr.close()
cnxn.commit()
When I run this code, I got an error message,
File "C:/Users/r/.PyCharmCE2018.3/config/scratches/Finalcombined2.py", line 64, in crsr.execute("""UPDATE Access.dbo.M_PWA SET P_PULSES=? WHERE DATETIME=?""", (row_list, aValue)) pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Column, parameter, or variable #1: Cannot find data type READONLY. (2715) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180); [42000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Parameter or variable '@P1' has an invalid data type. (2724)")
Please Help, thanks.