I am trying to build a server application which accepts input from user and queries the Microsoft Access database using the win32com object and serves the result.
The error occurs when I try to pass a variable inside my query instead of a string.
say if I run the code as
request_result = db.OpenRecordset("select * from Team_Ranks where Team = XYZ")
I get the correct result , but if I try
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)
or
request_result = db.OpenRecordset("select * from Team_Ranks where Team = your_team")
I get the following exception
File "C:\Documents and Settings\Shamayel\workspace\Team_Rank\db_test.py", line 9, in ?
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)
File "C:\Python24\Lib\site-packages\win32com\gen_py\00025E01-0000-0000-C000-000000000046x0x5x0.py", line 508, in OpenRecordset
ret = self._oleobj_.InvokeTypes(1610809383, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17)),Name, Type, Options, LockEdit)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'DAO.Database', 'Too few parameters. Expected 1.', 'jeterr40.chm', 5003061, -2146825227), None)
I have tried almost all different possibilties with hamdling the string variable but couldnt achieve a possible solution.
Any help would be appreciated.Thanks in advance
Just for reference sake, here's the entire code.
import win32com.client
engine = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase(r"c:\Team_rank\team_ranking.mdb")
your_team="XYZ"
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)
The error occurs when I try to pass a variable inside my query instead of a string.
say if I run the code as
request_result = db.OpenRecordset("select * from Team_Ranks where Team = XYZ")
I get the correct result , but if I try
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)
or
request_result = db.OpenRecordset("select * from Team_Ranks where Team = your_team")
I get the following exception
File "C:\Documents and Settings\Shamayel\workspace\Team_Rank\db_test.py", line 9, in ?
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)
File "C:\Python24\Lib\site-packages\win32com\gen_py\00025E01-0000-0000-C000-000000000046x0x5x0.py", line 508, in OpenRecordset
ret = self._oleobj_.InvokeTypes(1610809383, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17)),Name, Type, Options, LockEdit)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'DAO.Database', 'Too few parameters. Expected 1.', 'jeterr40.chm', 5003061, -2146825227), None)
I have tried almost all different possibilties with hamdling the string variable but couldnt achieve a possible solution.
Any help would be appreciated.Thanks in advance
Just for reference sake, here's the entire code.
import win32com.client
engine = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase(r"c:\Team_rank\team_ranking.mdb")
your_team="XYZ"
request_result = db.OpenRecordset("select * from Team_Ranks where Team = %s" %your_team)