[python-win32] FW: Problems with recordset object
David Hutto
smokefloat at gmail.com
Thu Sep 2 15:11:05 CEST 2010
On Thu, Sep 2, 2010 at 6:36 AM, Dardo Schuster Glez
<dardoschuster at hotmail.com> wrote:
> Dear Sirs
>
> I was programming many years with delphi/sql server and now i am looking
> python with your ado library to migrate . I am making my first ado program
> with python using python 3.1 and pythonwin but i have a problem : recordset
> can´t acces fields data i send you a sample and the answer from python
>
> # First import two useful modules
> import win32com.client
> from adoconstants import *
> # Create the ADO Connection object via COM.
> oConn = win32com.client.Dispatch('ADODB.Connection')
> # Now set the connection properties via the ConnectionString
> # We're connecting to a SQL Server on 192.168.1.100 using OLEDB.
> oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\personal.mdb;"
> # Now open the connection
> oConn.Open()
>
> if oConn.State == adStateOpen:
> # Do something here
> print ("We've connected to the database.")
> # Now create a RecordSet object and open a table
> rs = win32com.client.Dispatch('ADODB.Recordset')
> rs.Open("select * from agenda",oConn,1,3) # Open a table
> called agenda
> # Can also use oRS.Open("zipcode", oConn) instead of setting
> ActiveConnection
> print( repr(rs))
>
> while not rs.EOF:
> print (rs.fields("nombre"))
> # Move to the next record in the RecordSet
> rs.MoveNext()
>
> # Close up the connection and unload the COM object
> if oConn.State == adStateOpen: oConn.Close()
> oConn = None
>
>
> Answer from python
>
> We've connected to the database.
> <win32com.gen_py.Microsoft ActiveX Data Objects 2.8 Library._Recordset
> instance at 0x26371984>
> Traceback (most recent call last):
> File "C:\Dardo\Lenguaje Python\ado\Ejemplo\base-de-datos.py", line 27, in
> <module>
> print (rs.fields("nombre"))
I'm not positive but I think it's telling you that this rs has no
attribute fields. So us help(rs) and see if you're using it correctly
or maby you need to reference a class as well before using it.
> File "C:\Python31\lib\site-packages\win32com\client\__init__.py", line
> 462, in __getattr__
> raise AttributeError("'%s' object has no attribute '%s'" % (repr(self),
> attr))
> AttributeError: '<win32com.gen_py.Microsoft ActiveX Data Objects 2.8
> Library._Recordset instance at 0x26371984>' object has no attribute 'fields'
>
> Which is the problem ???
> Please answer a soon as posible
> Thanks
> Dardo R. Schuster
> Tenerife - canary islands - Spain
>
>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
More information about the python-win32
mailing list