pymssql 中文写入读取

 

问题解决来自于:前辈的一个文章

http://blog.csdn.net/kungbx/archive/2010/06/18/5678779.aspx

 

#!/usr/bin/env python

# -*- coding: gb2312 -*-

import pymssql

conn = pymssql.connect(host='192.168.5.100', user='sa', password='mssql', database='TEST',charset='cp936',as_dict=True)

cur = conn.cursor()

sql_b="INSERT INTO Table1 (id,name)VALUES('13','张文君')"

cur.execute(sql_b)

conn.commit()

sql_a='SELECT * FROM Table1'

# cur.execute(sql_a.encode('cp936'))

cur.execute(sql_a)

for name in cur.fetchall():

# print row

print name[0].encode('gbk')+name[1].encode('gbk')

conn.close()

 

你可能感兴趣的:(python)