Adding to an MS Access database using pyodbc

I am trying to add to a table called Users in an Access database I have created. I am using the following code to do it (which has been copied from here):

import pyodbc
def createAccount():
    conn = pyodbc.connect(r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=myPath\User Database.accdb;")
    cursor = conn.cursor()
    cursor.execute("""
            INSERT INTO Users(Username, Password, Chips)
            VALUES("User 5", "Pass 5", 7800)""")
    conn.commit()

but I get this error:

pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2. (-3010) (SQLExecDirectW)')

I've seen other posts which say to check spelling of all names used and there isn't anything wrong there. So why isn't this code working?



Read more here: https://stackoverflow.com/questions/66281539/adding-to-an-ms-access-database-using-pyodbc

Content Attribution

This content was originally published by TYG at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: