当前位置:网站首页>SQLServer连接数据库读取中文乱码问题解决
SQLServer连接数据库读取中文乱码问题解决
2022-07-06 00:06:00 【瘾ิۣۖิۣۖิۣۖิꦿ】
在一个大二的数据库课设,在一个月黑风高的晚上,我猛然发现,在pycharm终端出现了我从未见过的字符,原来是读取的中文显示出现了乱码,然后一顿操作猛如虎,开始疯狂百度,在两个小时后,我得到了问题的原因。
因为SQLServer不支持UTF-8,当使用varchar保存汉字时,会出现乱码,需要转换。
cast函数
我们将需要选择展示的列,利用cast函数,用nvarchar保存汉字,就可以解决中文乱码的问题
select cast(xx as nvarchar(20)) xxxx …
def showall(self):
self.model.removeRows(0, self.model.rowCount())
sql = "SELECT OwnerId,cast(OwnerName as nvarchar(20)),cast(OwnerSex as nvarchar(20)),OwnerBir,OwnerPhone,OwnerIdent,BuildId,RoomId FROM Owner"
self.cur.execute(sql)
rows = self.cur.fetchall()
print(rows)
self.addItem(rows)
边栏推荐
- Cloudcompare & PCL point cloud randomly adds noise
- 20220703 week race: number of people who know the secret - dynamic rules (problem solution)
- Qt QPushButton详解
- Knowledge about the memory size occupied by the structure
- Convert Chinese into pinyin
- Use mapper: --- tkmapper
- USB Interface USB protocol
- 7.5 装饰器
- What are the functions of Yunna fixed assets management system?
- Yunna | what are the main operating processes of the fixed assets management system
猜你喜欢
云呐|固定资产管理系统主要操作流程有哪些
XML配置文件(DTD详细讲解)
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
What are the functions of Yunna fixed assets management system?
Wechat applet -- wxml template syntax (with notes)
China Jinmao online electronic signature, accelerating the digitization of real estate business
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
Initialize your vector & initializer with a list_ List introduction
Priority queue (heap)
How much do you know about the bank deposit business that software test engineers must know?
随机推荐
FFMPEG关键结构体——AVFormatContext
XML配置文件(DTD详细讲解)
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
XML configuration file (DTD detailed explanation)
行列式学习笔记(一)
[binary search tree] add, delete, modify and query function code implementation
Tools to improve work efficiency: the idea of SQL batch generation tools
Detailed explanation of APP functions of door-to-door appointment service
【二叉搜索树】增删改查功能代码实现
Hudi of data Lake (1): introduction to Hudi
7.5 decorator
Key structure of ffmpeg - avformatcontext
FFMPEG关键结构体——AVFrame
Asynchronous task Whenall timeout - Async task WhenAll with timeout
Permission problem: source bash_ profile permission denied
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
14 MySQL view
Key structure of ffmpeg -- AVCodecContext
云呐|固定资产管理系统主要操作流程有哪些
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4