ADODB.RecordSet bummer ( was Re: Python and DB support (was: Re: Is Python Dead?))

Bill Bell bill-bell at bill-bell.hamilton.on.ca
Tue Jul 3 20:50:04 EDT 2001


Thanks, Bjorn.

I regret that when I tried the suggestion I got:

>>> rs.Fields("tableIndex").Value = 42
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "c:\python21\win32com\client\__init__.py", line 357, in 
__setattr__
    apply(self._oleobj_.Invoke, args + (value,) + defArgs)
com_error: (-2147352567, 'Exception occurred.', (0, 'ADODB.Field', 
'The operation requested by the application is not supported by the 
provider.', '', 0, -2146825037), None)

Also, there was a mistake in my post (there usually is). I should 
have written the lefthand side using square brackets, as I've have 
seen in a working example somewhere. However, this doesn't work 
either.

>>> rs["tableIndex"] = 42
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "c:\python21\win32com\client\__init__.py", line 348, in 
__getattr__
    raise AttributeError, attr
AttributeError: __setitem__

I did happen to find http://www.e-coli.net/pyado.html. This is 
verbatim almost from that page.

import win32com.client
conn = win32com.client.Dispatch(r'ADODB.Connection')
conn.Open('PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA 
SOURCE=C:\Program Files\WebPASS\webpass.mdb;')
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open('[URLs]', conn, 1, 3)
rs.Fields("tableIndex").Value = -2
rs.Update()
rs.Close()
conn.Close()

I'm relieved and grateful to be able to say that this works. It 
appears that my problem was with the connection string. The one I 
was using included mention of a "User DSN". Possibly that's the 
problem, I don't know. (Some of us have to live with much greater 
levels of ignorance than others. :o)

Thanks again.

Bill

On 3 Jul 2001, at 17:38, Bjorn Pettersen wrote:

> > From: Bill Bell [mailto:bill-bell at bill-bell.hamilton.on.ca]
> > 
> > [Martelli's address not included since many list members may 
> > already know it.]
> > 
> > Alex Martelli wrote, in part:
> > 
> > > you CAN write rs.Fields("FieldName").Value ... [and] ... I believe
> > > ADO (and much more so, COM:-) deserves a far better language than
> > > Visual Basic... Python, for example!-). 
> > 
> > Yup, me too FWIW. So, as one of this list's most longstanding 
> > newbies, I decided to give the combination a spin.
> > 
> > In VBA it's common to coin the cliche:
> > 
> > with myRecordSet
> > 	.edit
> > 	.fields('myField') = 42
> > 	.update
> > end with
> > 
> > Unfortunately,
> > 
> > >>> import win32com.client
> > >>> rs = win32com.client.Dispatch("ADODB.RecordSet")
> > >>> rs.ActiveConnection = "DSN=WebPASS"
> > >>> rs.Open("[URLs]")
> > >>> rs.Fields("myField") = 42
> > Traceback (SyntaxError: can't assign to function call
> > 
> > Or, is this because I forgot my medication this morning?
> 
> Try
> 
>   rs.Fields("myField").Value = 42
> 
> -- bjorn






More information about the Python-list mailing list