Discussion:
[python-win32] Attributes of win32com and accessing MS Access
Math
2006-02-06 18:43:25 UTC
Permalink
Hello,

Pardon my English, my native is Dutch.
Can somebody please tell me where I can find more information about win32com module and attributes.
I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python.
Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming?
Anybody any ideas or examples?

Thank you
Math
Tim Roberts
2006-02-06 21:09:36 UTC
Permalink
Post by Math
Pardon my English, my native is Dutch.
Can somebody please tell me where I can find more information about win32com module and attributes.
I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python.
Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming?
Anybody any ideas or examples?
There are actually two separate issues here. You must use the actual
Access application itself to create a brand-new database. The easiest
way to do that is to just fire up Access manually, create an empty
database, and save it. You cannot do that through ADO. It is certainly
manipulate Access from Python:

db = win32com.client.Dispatch("Access.Application")

However, I don't know the Access object model command for creating a new
database.

Once an empty database is created, you don't need to run Access any
more. You can do everything you need by driving ADODB or ODBC, and
there are lots of good examples on the web to show you how to do that.

conn = win32com.client.Dispatch("ADODB.Connection")

# Either way works: the first is the Jet OLEDB driver, the other is the
# Access ODBC driver.

db = r"c:\dev\54nsdc\Volunteer.mdb"
DSN="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db
#DSN="Driver={Microsoft Access Driver (*.mdb)};DBQ=" + db
conn.Open(DSN)

rs = win32com.client.Dispatch("ADODB.Recordset")
rs.Open( "[Committees]", conn, 1, 3 )

print rs.Fields.Count, " fields found:"
for x in range(rs.Fields.Count):
print rs.Fields.Item(x).Name,

That uses a table recordset, but it's just as easy to use SQL:

cmd = win32com.client.Dispatch("ADODB.Command")
cmd.ActiveConnection = conn

cmd.CommandText = "SELECT * FROM volunteers ORDER BY LastName;"
rs = cmd.Execute()[0]

rs.MoveFirst()
while not rs.EOF:
print rs.Fields("LastName")
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Math
2006-02-06 21:25:26 UTC
Permalink
I found a solution (Should be ADOX) :-):

How to create db.mdb in Pyton:

cat = win32com.client.Dispatch(r'ADOX.Catalog')
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb")

Thanks
-----------------------------------------------------------
Post by Tim Roberts
Post by Math
Pardon my English, my native is Dutch.
Can somebody please tell me where I can find more information about
win32com module and attributes.
I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python.
Where can I find all methods and so on from ****win32com*** when it comes
to DataVase prorgramming?
Anybody any ideas or examples?
There are actually two separate issues here. You must use the actual
Access application itself to create a brand-new database. The easiest
way to do that is to just fire up Access manually, create an empty
database, and save it. You cannot do that through ADO. It is certainly
db = win32com.client.Dispatch("Access.Application")
However, I don't know the Access object model command for creating a new
database.
Once an empty database is created, you don't need to run Access any
more. You can do everything you need by driving ADODB or ODBC, and
there are lots of good examples on the web to show you how to do that.
conn = win32com.client.Dispatch("ADODB.Connection")
# Either way works: the first is the Jet OLEDB driver, the other is the
# Access ODBC driver.
db = r"c:\dev\54nsdc\Volunteer.mdb"
DSN="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db
#DSN="Driver={Microsoft Access Driver (*.mdb)};DBQ=" + db
conn.Open(DSN)
rs = win32com.client.Dispatch("ADODB.Recordset")
rs.Open( "[Committees]", conn, 1, 3 )
print rs.Fields.Count, " fields found:"
print rs.Fields.Item(x).Name,
cmd = win32com.client.Dispatch("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM volunteers ORDER BY LastName;"
rs = cmd.Execute()[0]
rs.MoveFirst()
print rs.Fields("LastName")
--
Providenza & Boekelheide, Inc.
_______________________________________________
Python-win32 mailing list
http://mail.python.org/mailman/listinfo/python-win32
Math
2006-02-06 20:48:35 UTC
Permalink
I already found a solution :=).

----------------------------------------------
----- Original Message -----
From: Math
To: python-***@python.org
Sent: Monday, February 06, 2006 7:43 PM
Subject: [python-win32] Attributes of win32com and accessing MS Access


Hello,

Pardon my English, my native is Dutch.
Can somebody please tell me where I can find more information about win32com module and attributes.
I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python.
Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming?
Anybody any ideas or examples?

Thank you
Math

Continue reading on narkive:
Loading...