Post by MathPardon 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.