Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access database

Status
Not open for further replies.

1farooqui

Programmer
Jan 6, 2006
1
US
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)
 
What if you try:
request_result = db.OpenRecordset(str("select * from Team_Ranks where Team ='" + your_team = + "'"))

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top