そんなことができますか?私は以下を持っていますが、cursor.executeはselectSQLの構文が好きではありません。最終的に、.accdb 内のすべてのテーブルを反復処理し、各テーブルのレコードを同じテーブルとフィールドを持つ別の .accdb に挿入しようとしています。理由は、TabletPC 上のフィールド データ コレクションからサーバー上のマスター データベースに新しいレコードを持ち込むためです。
import pyodbc
connOtherDB = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='path to my dbase;")
otherDBtbls = connOtherDB.cursor().tables()
for t in otherDBtbls:
if t.table_name.startswith("tbl"): #ignores MS sys tables
cursor = connOtherDB.cursor()
#selectSQL = '"SELECT * from '+ str(t.table_name) + '"'
cursor.execute("SELECT * from tblDatabaseComments") #this works if I refer to a table by name
cursor.execute(selectSQL) #this does not work. throws SQL syntax error
row = cursor.fetchone()
if row:
print t.table_name
print row