odbc and accessing database results by field

Robert Brewer fumanchu at amor.org
Tue Oct 28 12:54:10 EST 2003


You can write:

c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
fieldNames = c.description
rows = c.fetchall()
c.close()
datadict = dict(zip(fieldNames, rows))
print datadict['field1']


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org

> -----Original Message-----
> From: JZ [mailto:jroznfgre at jngpugbjreQBGbet.cy] 
> Sent: Tuesday, October 28, 2003 7:26 AM
> To: python-list at python.org
> Subject: odbc and accessing database results by field
> 
> 
> import odbc
> conn = odbc.odbc('mydsn')
> c = conn.cursor()
> c.execute('SELECT TOP 10 field1, field2 FROM TABLE')
> rows = c.fetchall()
> c.close()
> conn.close()
> 
> I am using MSSQL2000. My problem is:
> Instead of row[0], rows[1] 
> I would like to use row['field1], row['field']
> Is it possible for odbc module?
> I cannot find any comprehensive documentation :(
> 
> --
> JZ ICQ:6712522
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list