insertintodbo.testvalues(1,2,3,4,5,6,7)能成功插入,每个字段都是unicode字符型。insertintodbo.testvalues(u'中文',1,2,3,4,5,6),这样就会报错,pymssql.ProgrammingError:(102,"I...
insert into dbo.test values(1,2,3,4,5,6,7)能成功插入,每个字段都是unicode字符型。
insert into dbo.test values(u'中文',1,2,3,4,5,6),这样就会报错,pymssql.ProgrammingError: (102, "Incorrect syntax near '\xe9\x87\x8d\xe5\xba\x86'.DB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
为什么啊?怎么才能不报错呢?
insert into dbo.test values("中文",1,2,3,4,5,6)就行了。但是python操作数据库,这样直接插入数据,数据库能看到数据。但是,如果传参插入,就没数据,也不报错。。。求解
cnn=pymssql.connect(host='192.168.201.210',user='sa',password='123456',port='1433',database='xwqy',charset='utf8')
cursor=cnn.cursor()
sql='INSERT INTO dbo.test VALUES (%s,%s)'
for item in items:
i2=item['regno']
i1=item['entname']
print i1,i2
param=(i1,i2)
cursor.execute(sql,param)
print cursor
cursor.close()
cnn.close()
展开