pyodbc reads fine, but won't update a value?...

12050
2
Jump to solution
10-31-2014 10:24 AM
KevinBell
Occasional Contributor III

Hi all!  HELP!   : )

I'm able to read rows from SQL Server just fine with pyodbc, but I can't seem to update a row.  Any ideas?  At this point there's no gis involvement here, but there will be once I can modify the table.

import pyodbc

cstring = 'DRIVER={SQL Server};SERVER=aServer;DATABASE=aDatabase;UID=aUN;PWD=aPassword'

con = pyodbc.connect(cstring)

cur = con.cursor()

sql = """UPDATE Stats SET myColumn = 'TEST' WHERE case_number = 'case9999'"""

rows = cur.execute(sql).fetchall()

con.commit()

cur.close()

del cur, con

>>>pyodbc.ProgrammingError: No results.  Previous SQL was not a query.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III

The error message says it all. An UPDATE statement doesn’t return rows. You can execute() without calling fetchall().

View solution in original post

0 Kudos
2 Replies
JasonScheirer
Occasional Contributor III

The error message says it all. An UPDATE statement doesn’t return rows. You can execute() without calling fetchall().

0 Kudos
KevinBell
Occasional Contributor III

You are the coolest!  I normally am only reading these tables, so now I can go have some fun!

0 Kudos