0
我正在嘗試使用pypyodbc從SQL Server數據庫提取數據。 但是,當我試圖建立使用SELECT語句看來我的代碼休息pypyodbc:問題
myCursor.execute(SQLCommand,values)
任何人都可以發現一個問題,指出我在正確的方向?
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')
乾杯 史蒂夫
拿出'try' ...'除了'並向我們展示回溯。 – cco
OK - varchar與=運算符不兼容。用「LIKE」排序取代=。感謝指針重新刪除「嘗試/除外」以查看回溯。新手學習:) – Steve