[python-win32] FW: Problems with recordset object
vernondcole at gmail.com
Thu Sep 2 23:09:16 CEST 2010
Why are you going to all this work?
You could simply...
which has all of the COM interface things already written.
There is a new version which has the ability to access columns by name, and
which uses objects to read data directly from the recordset (rather than
copying data into Python tuples.) You can pick it up from
http://sourceforge.net/projects/adodbapi/ -- that installer will replace the
copy which comes with pywin32.
It passes all of the tests (including reading and writing ACCESS tables) --
but someone trying the new features in a new application would be very
welcome. Unit tests can miss things. Please try it out and let me (and
everyone else) know how it works for you.
On Thu, Sep 2, 2010 at 4: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
> # Now open the connection
> 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
> print( repr(rs))
> while not rs.EOF:
> print (rs.fields("nombre"))
> # Move to the next record in the RecordSet
> # 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
> print (rs.fields("nombre"))
> File "C:\Python31\lib\site-packages\win32com\client\__init__.py", line
> 462, in __getattr__
> raise AttributeError("'%s' object has no attribute '%s'" % (repr(self),
> 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
> Dardo R. Schuster
> Tenerife - canary islands - Spain
> python-win32 mailing list
> python-win32 at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the python-win32