吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4261|回复: 3
收起左侧

[Python 转载] python操作Sqlserver数据库

  [复制链接]
18382747915 发表于 2018-9-12 09:30
[Python] 纯文本查看 复制代码
import pymssql
# server    数据库服务器名称或IP
# user      用户名
# password  密码
# database  数据库名称

conn=pymssql.connect(host='127.0.0.1',charset='utf8',user='sa',password='123',database='book')

cursor = conn.cursor()
# 查询操作
pd = True
cursor.execute('SELECT zhanghao,mima FROM yonghubiao')
cam_rows = cursor.fetchall()
if not cam_rows:
    print("查询出来的数据为空")
else:

   while pd:
        zhanghao = input("请输入你的账号:")
#只写了查询和添加的代码,更新和删除跟添加一样,只是SQL语句不同
        
mima = input("请输入你的密码:")        for row in  cam_rows:
              if zhanghao==row[0].strip() and mima==row[1].strip(): #strip() 移除字符串所有空格
                   print("账号密码正确")
                   pd=False



print("进入主菜单")
#添加操作
# cursor.execute("insert into yonghubiao(zhanghao,mima) values('zsda','asa555')")
# conn.commit()
# if cursor.rowcount>0:
#     print("成功插入%s条数据" %cursor.rowcount)
# else:
#     print("插入失败")

# 关闭连接
conn.close()

免费评分

参与人数 3吾爱币 +3 热心值 +3 收起 理由
787821 + 1 + 1 正需要sqlserver的连接方式呢。不知道楼主有没有好的gui教程分享下,tkinter.
lin_xop + 1 + 1 热心回复!
ZMing + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

蔚蓝色 发表于 2018-9-12 10:04
看看,最近也在学Python
wdlcshpzjfxx 发表于 2018-9-12 11:55
小黑LLB 发表于 2019-2-12 10:30
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-21 12:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表