<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Phill Atwood wrote:
<blockquote cite="mid4415FA95.9040309@phillatwood.name" type="cite"><br>
Thanks. I've downloaded and installed adodb for Python. But I guess I
need to install mxODBC as well. But I'm not quite understanding the
docs I'm reading on how to do this. It seems very complex....
<br>
</blockquote>
<br>
No, you don't need mxODBC, although I'm curious to know what led you to
believe that. Go do a google search for "adodb connection strings",
and you find several samples. Here's a simple sample that I used to
access an Access database. Note that I have connection strings for
either the Jet OLEDB driver, or the Access ODBC driver. This opens a
"table" recordset (the rs.Open function).<br>
<tt><br>
</tt>
<blockquote><tt>import os</tt><br>
<tt>import win32com.client</tt><br>
<br>
<tt>conn = win32com.client.Dispatch("ADODB.Connection")</tt><br>
<br>
<tt># Either way works: one is the Jet OLEDB driver, the other is the
</tt><br>
<tt># Access ODBC driver. OLEDB is probably better.</tt><br>
<br>
<tt>db = r"c:\dev\54nsdc\Volunteer.mdb"</tt><br>
<tt>DSN="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db</tt><br>
<tt>#DSN="Driver={Microsoft Access Driver (*.mdb)};DBQ=" + db</tt><br>
<tt>conn.Open(DSN)</tt><br>
<br>
<tt>rs = win32com.client.Dispatch("ADODB.Recordset")</tt><br>
<tt>rs.Open( "[Committees]", conn, 1, 3 )</tt><br>
<br>
<tt>print rs.Fields.Count, " fields found:"</tt><br>
<tt>for x in range(rs.Fields.Count):</tt><br>
<tt> print rs.Fields.Item(x).Name,</tt><br>
<tt> print rs.Fields.Item(x).Type,</tt><br>
<tt> print rs.Fields.Item(x).DefinedSize,</tt><br>
<tt> print rs.Fields.Item(x).Value</tt><br>
</blockquote>
<tt><br>
<br>
</tt>To execute a generic SQL statement, you create an ADODB.Command
object and connect it to the Connection:<br>
<br>
<blockquote><tt>cmd = win32com.client.Dispatch("ADODB.Command")</tt><br>
<tt>cmd.ActiveConnection = conn</tt><br>
<tt>cmd.CommandText = "SELECT COUNT(*) FROM committees;"</tt><br>
<tt>rs = cmd.Execute[0]</tt><br>
</blockquote>
<br>
Now rs is a recordset.<br>
<pre class="moz-signature" cols="72">--
Tim Roberts, <a class="moz-txt-link-abbreviated" href="mailto:timr@probo.com">timr@probo.com</a>
Providenza & Boekelheide, Inc.
</pre>
</body>
</html>