Using ADO in Python
Bill Tutt
billtut at microsoft.com
Sat May 13 07:01:06 EDT 2000
> From: alien at netspace.net.au [mailto:alien at netspace.net.au]
>
>
> I can create an ADODB.Recordset object and use it under Python. No
> problem. But how do I use a recordset returned, for example, from
> Connection.Execute()?
>
> When I try something like:
>
> import win32com.client
>
> con = win32com.client.Dispatch("ADODB.Connection")
> con.Open("Provider=SQLOLEDB.1;Password=password;Persist Security
> Info=True;User ID=sa;Initial Catalog=Surefire;Data Source=ARMALYTE")
> rs = win32com.client.Dispatch("ADODB.Recordset")
> print rs.State
> rs = con.Execute("SELECT * FROM Stock WHERE Stock_Unique_Id IS NULL")
> print rs.State
>
> I get the error:
>
> Traceback (innermost last):
> File "F:\Code\Python\ado.py", line 8, in ?
> print rs.State
> AttributeError: 'tuple' object has no attribute 'State'
>
> The first "print rs.State" works, the second does not.
>
> Any help would be appreciated.
>
Execute is returning a tuple.
Replace the 2nd "print rs.State" with "print rs" and you'll see whats going
on.
The reason that Execute is returning a tuple is because Execute has an out
parameter besides the normal recordset return value.
Something like rs = con.Execute(....)[0] might do the trick.
Bill
More information about the Python-list
mailing list