I have this table in Windows Access:
The title of my table is DATA
NAME - GENDER - NUMBER
Jo - Male - 1
Ali - Male - 2
MO - Male - 3
I want to use an input that asks a name and I want my program to give the details of that person.
I tried to do this:
import pyodbc
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};' +
r'DBQ=C:\Users\Gebruiker\PycharmProjects\TennisDatabase.accdb;')
gegevens = conn.cursor()
question = input("Give a name: ")
SelectString = 'SELECT NAME FROM DATA WHERE DATA.NAME = ' + question + ';'
gegevens.execute(SelectString)
gegevensList = gegevens.fetchall()
print(len(gegevensList), "Spelergegevens : ")
for gegevens in gegevensList:
print (gegevens)
print('')
I get this error:
Traceback (most recent call last): File "C:/Users/Gebruiker/PycharmProjects/Opdracht 1.py", line 9, in gegevens.execute(SelectString) pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')
I have no clue what I am doing wrong and how to fix it. Can anyone help me how to do this?
SelectStringthequestionis replaced with the input value. However, the variable call is inside a string and thus you are not actually getting the value. Try'SELECT NAME FROM DATA WHERE DATA.NAME = ' + question + ';'. It is not going to solve you main problem but it still needs to be fixed