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@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to