Python连接SqlServer练习记录

import pymssql

#connect database
conn=pymssql.connect(host="192.168.1.28",user="boomink",password="boomink",
database="boomink")

 

cur=conn.cursor()

 

print '========================================'

 

cur.execute("exec Orders_GetTest1 @Value=%s ",('2005-01-01',))

 

while 1:
print cur.fetchall()
if 0 == cur.nextset():
break

data=cur.fetchall()

print data

 

print '========================================'

 

#cur.execute("exec Orders_GetTest")
cur.execute("exec Orders_GetTest2 @Value1=%s,@Value2=%s",('Ruan','Yu'))

while 1:
print cur.fetchall()

if 0 == cur.nextset():
break

data=cur.fetchall()

print data

 

print '========================================'

cur.execute("exec Orders_GetTracking @BeginDate=%s,@EndDate=%s",('2005-01-01','2008-01-01'))

 

record = cur.fetchall()

 

while 1:
print cur.nextset()

for r in record:
print '========================================'
a=r[1]
print 'OrderId:%s' % r[0]

print r
print '========================================'

if 0 == cur.nextset():
break

 

print "rnrow count:%d" % cur.rowcount

 

 

#commit the connection
conn.commit

 

#close the connection
conn.close

你可能感兴趣的:(sqlserver)