[python-win32] FW: Problems with recordset object

Vernon Cole vernondcole at gmail.com
Thu Sep 2 23:09:16 CEST 2010


Dardo:
  Why are you going to all this work?

You could simply...
import adodbapi
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.
--
Vernon Cole

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
> 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"))
>   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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100902/5cdbcaf6/attachment-0001.html>


More information about the python-win32 mailing list