ADO in MS-IIS with MS-SQL Server

msrisney at ingr.com msrisney at ingr.com
Thu Oct 14 04:21:34 EDT 1999


here are some samples, David Sparrman has some good examples, at
http://personal.byggdok.se/~ds/python/ as well, good luck.

BTW, for some reason I have found relatively little documentation on 
ADO and Python, anyone intersted in writing up a tutorial???





import win32com.client
from win32com.client import constants


db=win32com.client.Dispatch("ADODB.Connection")
rs=win32com.client.Dispatch("ADODB.Recordset")

# ODBC  DSN,User,PWD
db.Open('Joust','','')


# create a table
print "Creatin a table with two columns, col1, and col2"
db.Execute("create table python_table (col1 varchar(25), col2 int)")


# Open recordset and insert one record
print "Inserting one record into python_table"
rs.Open("python_table", db, constants.adOpenDynamic,
constants.adLockOptimistic, constants.adCmdTable)
rs.AddNew()
rs.Fields("col1").Value="scott"
rs.Fields("col2").Value=123
rs.Update()
rs.Close()





# Since the table just was created it contains only one record
rs.Open("SELECT col1, col2 FROM python_table", db)
print "Retreived data:"
print "     Name = ", rs.Fields("col1").Value
print "    value = ", rs.Fields("col2").Value
print "Dropping table"
db.Execute("drop table python_table")
rs.Close()
db.Close()
print "All done!"






More information about the Python-list mailing list