Hi
I'm using activestate python 2.4 on win xp 2 ed. and Ms Access 2002
(reading first http://starship.python.net/crew/bwilk/access.html)
I have writed the following code
def append_from_Access(self):
try:
import ...
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=C:/Afile.mdb;"
conn.Open(DSN)
except Exception, inst:
...
try:
sql_statement='SELECT * FROM Mytable'
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(sql_statement, conn, 1, 3)
while not rs.EOF:
id=rs.Fields(colName.Value) #colName, valid column name
...
rs.MoveNext()
rs.Close()
conn.Close()
except Exception, inst:
...
I'm using it for reading tables or queries in a mdb file.
With some mdb it works fine and return a no empty recordset, but with
others mdb files, the recordsets are void (opening the tables or
recorsets with Ms Access are not void).
Some help is welcome,
Thanks in advance
Luis 8 3271
luis wrote: Hi I'm using activestate python 2.4 on win xp 2 ed. and Ms Access 2002 (reading first http://starship.python.net/crew/bwilk/access.html) I have writed the following code
def append_from_Access(self): try: import ... conn = win32com.client.Dispatch(r'ADODB.Connection') DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/Afile.mdb;" conn.Open(DSN) except Exception, inst: ... try: sql_statement='SELECT * FROM Mytable' rs = win32com.client.Dispatch(r'ADODB.Recordset') rs.Open(sql_statement, conn, 1, 3) while not rs.EOF: id=rs.Fields(colName.Value) #colName, valid column name ... rs.MoveNext() rs.Close() conn.Close()
except Exception, inst: ...
I'm using it for reading tables or queries in a mdb file. With some mdb it works fine and return a no empty recordset, but with others mdb files, the recordsets are void (opening the tables or recorsets with Ms Access are not void). Some help is welcome, Thanks in advance Luis
I don't know if it's the problem your asking about, but your
rs.MoveNext() should be inside the while loop, no?
Iain
Iain King ha escrito: luis wrote: Hi I'm using activestate python 2.4 on win xp 2 ed. and Ms Access 2002 (reading first http://starship.python.net/crew/bwilk/access.html) I have writed the following code
def append_from_Access(self): try: import ... conn = win32com.client.Dispatch(r'ADODB.Connection') DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/Afile.mdb;" conn.Open(DSN) except Exception, inst: ... try: sql_statement='SELECT * FROM Mytable' rs = win32com.client.Dispatch(r'ADODB.Recordset') rs.Open(sql_statement, conn, 1, 3) while not rs.EOF: id=rs.Fields(colName.Value) #colName, valid column name ... rs.MoveNext() rs.Close() conn.Close()
except Exception, inst: ...
I'm using it for reading tables or queries in a mdb file. With some mdb it works fine and return a no empty recordset, but with others mdb files, the recordsets are void (opening the tables or recorsets with Ms Access are not void). Some help is welcome, Thanks in advance Luis I don't know if it's the problem your asking about, but your rs.MoveNext() should be inside the while loop, no?
Yes, is inside Iain
luis wrote: Iain King ha escrito:
luis wrote: while not rs.EOF: id=rs.Fields(colName.Value) #colName, valid column name ... rs.MoveNext() rs.Close() conn.Close()
I don't know if it's the problem your asking about, but your rs.MoveNext() should be inside the while loop, no? Yes, is inside
You mean, it is inside the while loop in your code, but you made a
mistake copying it into your post? In the code you posted it is not
inside the while loop - it would have to be indented one more level for
that.
Iain
Iain King ha escrito: luis wrote: Iain King ha escrito:
luis wrote: > while not rs.EOF: > id=rs.Fields(colName.Value) #colName, valid column name > ... > rs.MoveNext() > rs.Close() > conn.Close()
I don't know if it's the problem your asking about, but your rs.MoveNext() should be inside the while loop, no? Yes, is inside
You mean, it is inside the while loop in your code, but you made a mistake copying it into your post? In the code you posted it is not inside the while loop - it would have to be indented one more level for that.
Iain
this is te correct identation
def append_from_Access(self):
try:
import ...
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=C:/Afile.mdb;"
conn.Open(DSN)
except Exception, inst:
...
try:
sql_statement='SELECT * FROM Mytable'
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(sql_statement, conn, 1, 3)
while not rs.EOF:
id=rs.Fields(colName.Value) #colName, valid column name
...
rs.MoveNext()
rs.Close()
conn.Close()
except Exception, inst:
...
I think my problem must be with ado and dao.
Now I have run makepy utility and select Microsoft ActiveX Data Objects
2.5 Library, perhaps I must also select Microsoft DAO3.5 Object Library
and write
win32com.client.Dispatch("DAO.DBEngine.35") for Access 97 or
win32com.client.Dispatch(r'ADODB.Connection') for Acess 2000
Do you know is it possible ?
luis
luis wrote: Iain King ha escrito:
luis wrote: Iain King ha escrito:
> luis wrote: > > while not rs.EOF: > > id=rs.Fields(colName.Value) #colName, valid column name > > ... > > rs.MoveNext() > > rs.Close() > > conn.Close() > > I don't know if it's the problem your asking about, but your > rs.MoveNext() should be inside the while loop, no? Yes, is inside >
You mean, it is inside the while loop in your code, but you made a mistake copying it into your post? In the code you posted it is not inside the while loop - it would have to be indented one more level for that.
Iain
this is te correct identation
def append_from_Access(self): try: import ... conn = win32com.client.Dispatch(r'ADODB.Connection') DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:/Afile.mdb;" conn.Open(DSN) except Exception, inst: ... try: sql_statement='SELECT * FROM Mytable' rs = win32com.client.Dispatch(r'ADODB.Recordset') rs.Open(sql_statement, conn, 1, 3) while not rs.EOF: id=rs.Fields(colName.Value) #colName, valid column name ... rs.MoveNext() rs.Close() conn.Close()
except Exception, inst: ...
I think my problem must be with ado and dao. Now I have run makepy utility and select Microsoft ActiveX Data Objects 2.5 Library, perhaps I must also select Microsoft DAO3.5 Object Library and write win32com.client.Dispatch("DAO.DBEngine.35") for Access 97 or win32com.client.Dispatch(r'ADODB.Connection') for Acess 2000 Do you know is it possible ? luis
Well, without being able to test on your system I don't think I can
give you any real advice. This is the module I use to interface with
Access:
Access.py
---------------
import win32com.client
from win32com.client import constants
def isWriteable(field):
"""Is given Field writeable?"""
return field.Attributes & 4
class Access(object):
def __init__(self, filename, password=""):
self._filename = filename
self._connection = win32com.client.Dispatch(r'ADODB.Connection')
if password:
self._DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=%s;Jet
OLEDB:Database Password=%s;' % (filename, password)
else:
self._DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=%s;' %
(filename)
def Query(self, query):
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
fields = []
for x in xrange(rs.Fields.Count):
fields.append(rs.Fields(x).Name)
if rs.EOF:
data = []
else:
data = rs.GetRows()
rs.Close()
self._connection.Close()
return fields, data
def Add(self, table, records):
"""Adds records to table."""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(table, self._connection, 1, 3)
unwriteables = []
for record in records:
rs.AddNew()
unwriteable = []
for i in xrange(len(record)):
if isWriteable(rs.Fields(i)):
rs.Fields(i).Value = record[i]
else:
unwriteable.append(rs.Fields(i).Value)
unwriteables.append(unwriteable)
rs.Update()
rs.Close()
self._connection.Close()
return unwriteables
def Update(self, query, function):
"""Updates all records found in query with function(record)"""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
columns = rs.Fields.Count
while not rs.EOF:
record = []
for i in xrange(columns):
record.append(rs.Fields(i).Value)
newRecord = function(record[:])
for i in xrange(columns):
if isWriteable(rs.Fields(i)):
rs.Fields(i).Value = newRecord[i]
rs.MoveNext()
rs.Close()
self._connection.Close()
def Delete(self, query):
"""Deletes all records found in query"""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
while not rs.EOF:
rs.Delete()
rs.MoveNext()
rs.Close()
self._connection.Close()
We only have Access 2000+, so I don't know if it'll work with prior
versions.
Iain
Iain King ha escrito:
luis wrote:
Iain King ha escrito:
luis wrote:
Iain King ha escrito:
luis wrote:
while not rs.EOF:
id=rs.Fields(colName.Value) #colName, valid column name
...
rs.MoveNext()
rs.Close()
conn.Close()
>
I don't know if it's the problem your asking about, but your
rs.MoveNext() should be inside the while loop, no?
Yes, is inside
>
>
You mean, it is inside the while loop in your code, but you made a
mistake copying it into your post? In the code you posted it is not
inside the while loop - it would have to be indented one more level for
that.
>
Iain
this is te correct identation
def append_from_Access(self):
try:
import ...
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=C:/Afile.mdb;"
conn.Open(DSN)
except Exception, inst:
...
try:
sql_statement='SELECT * FROM Mytable'
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(sql_statement, conn, 1, 3)
while not rs.EOF:
id=rs.Fields(colName.Value) #colName, valid column name
...
rs.MoveNext()
rs.Close()
conn.Close()
except Exception, inst:
...
I think my problem must be with ado and dao.
Now I have run makepy utility and select Microsoft ActiveX Data Objects
2.5 Library, perhaps I must also select Microsoft DAO3.5 Object Library
and write
win32com.client.Dispatch("DAO.DBEngine.35") for Access 97 or
win32com.client.Dispatch(r'ADODB.Connection') for Acess 2000
Do you know is it possible ?
luis
Well, without being able to test on your system I don't think I can
give you any real advice. This is the module I use to interface with
Access:
Access.py
---------------
import win32com.client
from win32com.client import constants
def isWriteable(field):
"""Is given Field writeable?"""
return field.Attributes & 4
class Access(object):
def __init__(self, filename, password=""):
self._filename = filename
self._connection = win32com.client.Dispatch(r'ADODB.Connection')
if password:
self._DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=%s;Jet
OLEDB:Database Password=%s;' % (filename, password)
else:
self._DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=%s;' %
(filename)
def Query(self, query):
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
fields = []
for x in xrange(rs.Fields.Count):
fields.append(rs.Fields(x).Name)
if rs.EOF:
data = []
else:
data = rs.GetRows()
rs.Close()
self._connection.Close()
return fields, data
def Add(self, table, records):
"""Adds records to table."""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(table, self._connection, 1, 3)
unwriteables = []
for record in records:
rs.AddNew()
unwriteable = []
for i in xrange(len(record)):
if isWriteable(rs.Fields(i)):
rs.Fields(i).Value = record[i]
else:
unwriteable.append(rs.Fields(i).Value)
unwriteables.append(unwriteable)
rs.Update()
rs.Close()
self._connection.Close()
return unwriteables
def Update(self, query, function):
"""Updates all records found in query with function(record)"""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
columns = rs.Fields.Count
while not rs.EOF:
record = []
for i in xrange(columns):
record.append(rs.Fields(i).Value)
newRecord = function(record[:])
for i in xrange(columns):
if isWriteable(rs.Fields(i)):
rs.Fields(i).Value = newRecord[i]
rs.MoveNext()
rs.Close()
self._connection.Close()
def Delete(self, query):
"""Deletes all records found in query"""
self._connection.Open(self._DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs.Open(query, self._connection, 1, 3)
while not rs.EOF:
rs.Delete()
rs.MoveNext()
rs.Close()
self._connection.Close()
We only have Access 2000+, so I don't know if it'll work with prior
versions.
Iain
Thanks, for your code
My problem was opening a query (not a table) on mdb file
1) If the query includes a where clause type
field1="edf" and field2=3
, for example, no problem, Access can retrieve a not empty recordset
and my python code too.
2) But if the Access's query includes a LIKE clause, for example
field1="e*"
, Access can retrieves a not empty recordset but my python code
retrieves a empty recordset.
If I write the WHERE clause inside my python code, the recorset returns
an non empty recordset. Perhaps the problem was the different use of *
and % in Access and SQL, I don't know.
Luis
luis wrote:
My problem was opening a query (not a table) on mdb file
1) If the query includes a where clause type
field1="edf" and field2=3
, for example, no problem, Access can retrieve a not empty recordset
and my python code too.
2) But if the Access's query includes a LIKE clause, for example
field1="e*"
, Access can retrieves a not empty recordset but my python code
retrieves a empty recordset.
Which is exactly what it _should_ return on that query, unless you have
records with "e*" in column field1.
The proper SQL clause is:
... WHERE field1 LIKE 'e*' ...
But, you did not include that part of the program, so you wound up
crippling those who were willing to try to help you, because you
thought you kinda-sorta knew what was going on (but not enough to
fix it). Find "smart questions" and read it a couple of times.
--
--Scott David Daniels sc***********@acm.org
>, Access can retrieves a not empty recordset but my python code
>retrieves a empty recordset.
Which is exactly what it _should_ return on that query, unless you have
records with "e*" in column field1.
The proper SQL clause is:
... WHERE field1 LIKE 'e*' ...
which would also return an empty recordset unless the OP has
records with "e*" in column field1...
the proper SQL clause would be
... WHERE field1 LIKE 'e%' ...
(in SQL, the "%" and "_" are used as wildcards, not asterisk and
question-mark respectively as they are in most shell expansions)
:)
-tkc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AG |
last post by:
I want to connect over the internet to get data from clients.What would
be the easiest method and the most stable methos to do it
1.Use a Point to Point prtotcol from the client pc and then...
|
by: zumbar |
last post by:
hi,
I am writing a java application that connects to a MS Access databse
with two fields , Date and amount. I can insert into this datbase
using the application.
Now , I need to retrieve weekly...
|
by: amjad |
last post by:
Hi when i try below code
public DataSet GetData(string ConString)
{
OracleDataAdapter da;
DataSet ds = new DataSet();
// Setup connection string to access Oracle 9i
|
by: PraveenKadkol |
last post by:
Hi,
My Development is in almost final stages, now i am facing problem with the reports.
I am generating MsAccess Reports based on the selected Parameters, while generating Report I am opening ...
|
by: =?Utf-8?B?cGVsZWdrMQ==?= |
last post by:
i am trying to conenct oto sql server 2005
when i do it i the VS2005 every is ok
but when i run from the browser i get :
The login failed. Login failed for user 'JUSTATHOME\ASPNET'.
i read this...
| |
by: pradeep84 |
last post by:
hi.. to all..
i hav created the applet program codes inorder to save the data in the database.... now i hav to view the data using applets.. any specific method is there.... to do that..
...
|
by: daffurankan |
last post by:
HAi ,
this ankan wanted to know the code how can i change access database password through vb 6.0 code.
|
by: laurence |
last post by:
hi,
i am new in vb. i am not finding the way to connect ms access database to visual basic.
what i need is i need to take data from msaccess and calculation will be done in vb and the result page...
|
by: ZyON |
last post by:
I wrote this code in asp.net(vb):
dim dbconn as New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("../kri1.mdb"))
Dim DBCmd As New OleDbCommand
Dim DBAdap As...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |