I am trying to extract data from a SQL Server Database using pypyodbc. But it appears my code breaks when I try to construct the SELECT Statement using
myCursor.execute(SQLCommand,values)
Can anyone spot an issue and point me in the right direction?
import pypyodbc
try:
myConnection = pypyodbc.connect('Driver={SQL Server};'
'Server=THINKPAD\STEVE_DEVELOPER;'
'Database=PythonTest;'
'uid=sa; pwd=passwordCC')
myCursor = myConnection.cursor()
print("Connection Made")
SQLCommand =("SELECT First_Name, Date FROM [PythonTest].[dbo].[Names] WHERE First_Name =?")
values = ['Mike']
print("SQL command elements Created")
#After this is where it falls over
myCursor.execute(SQLCommand,values)
print("SQL statement constructed ")
results = myCursor.fetchone()
print(results[0])
print("Sucessfully retreive record")
myconnection.close()
except:
print('Record NOT sucessfully retreived')
Cheers Steve