python数据库编程 ODBC方式实现通讯录


Posted in Python onMarch 27, 2020

Python 数据库编程,ODBC方式实现通讯录,供大家参考,具体内容如下

#-*-coding:utf-8-*-
import pyodbc
import os
def SelectInfo(hcon,hcur):
 hcur.execute('select * from PassMapT')
 ptitle=('ID','Item','Pwd','other')
 print(ptitle)
 result=hcur.fetchall()
 for item in result:
 print(item)
 print('')

def AddInfo(hcon,hcur):
 id=int(input('please input ID: '))
 item=str(input('please input Item: '))
 pwd=str(input('please input Tel 1: '))
 other=str(input('please input Other: '))
 sql="insert into PassMapT(id,item,pwd,other) values(?,?,?,?)"
 try:
 hcur.execute(sql,(id,item,pwd,other))
 hcon.commit()
 except:
 hcon.rollback()

def DeleteInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of delete: '))
 sql="delete from PassMapT where id=?"
 try:
 hcur.execute(sql,(did,))
 hcon.commit()
 except:
 hcon.rollback()

def UpdateInfo(hcon,hcur):
 SelectInfo(hcon,hcur)
 did=int(input('please input id of update: '))
 
 sqlitem="update PassMapT set item=? where id=?"
 item=str(input('please input Item: '))
 try:
 hcur.execute(sqlitem,(item,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlpwd="update PassMapT set pwd=? where id=?"
 pwd=str(input('please input Pwd: '))
 try:
 hcur.execute(sqlpwd,(pwd,did))
 hcon.commit()
 except:
 hcon.rollback()
 
 sqlother="update PassMapT set other=? where id=?"
 other=str(input('please input other: '))
 try:
 hcur.execute(sqlother,(other,did))
 hcon.commit()
 except:
 hcon.rollback()
 
def Meau():
 print('1.diaplay')
 print('2.add')
 print('3.update')
 print('4.delete')
 print('5.cls')
 print('0.exit')
 sel=9
 while(sel>5 or sel<0):
 sel=int(input('please choice: '))
 return sel

def main():
 hcon = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=127.0.0.1;DATABASE=PasswordMap;UID=sa;PWD=lptpwd')
 hcur=hcon.cursor()
 
 while(True):
 sel=Meau()
 if(sel==1):
 SelectInfo(hcon,hcur)
 elif(sel==2):
 AddInfo(hcon,hcur)
 elif(sel==3):
 UpdateInfo(hcon,hcur)
 elif(sel==4):
 DeleteInfo(hcon,hcur)
 elif(sel==5):
 os.system('cls')
 else:
 break
 hcur.close()
 hcon.close()

if __name__=='__main__':
 main()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python三元运算符实现方法
Dec 17 Python
Python两个整数相除得到浮点数值的方法
Mar 18 Python
对Python3 解析html的几种操作方式小结
Feb 16 Python
python3.7 使用pymssql往sqlserver插入数据的方法
Jul 08 Python
Python实现Singleton模式的方式详解
Aug 08 Python
OpenCV模板匹配matchTemplate的实现
Oct 18 Python
python根据文本生成词云图代码实例
Nov 15 Python
python标准库OS模块详解
Mar 10 Python
python实现文件分片上传的接口自动化
Nov 19 Python
如何用Python提取10000份log中的产品信息
Jan 14 Python
matplotlib源码解析标题实现(窗口标题,标题,子图标题不同之间的差异)
Feb 22 Python
python开发制作好看的时钟效果
May 02 Python
django 读取图片到页面实例
Mar 27 #Python
django ListView的使用 ListView中获取url中的参数值方式
Mar 27 #Python
django列表筛选功能的实现代码
Mar 27 #Python
python实现猜数游戏
Mar 27 #Python
手把手教你安装Windows版本的Tensorflow
Mar 26 #Python
python pandas.DataFrame.loc函数使用详解
Mar 26 #Python
Python计算指定日期是今年的第几天(三种方法)
Mar 26 #Python
You might like
smarty内置函数capture用法分析
2015/01/22 PHP
javascript 拖动表格行实现代码
2011/05/05 Javascript
Extjs4 类的定义和扩展实例
2013/06/28 Javascript
基于jQuery实现以手风琴方式展开和折叠导航菜单
2016/01/28 Javascript
Bootstrap carousel轮转图的使用实例详解
2016/05/17 Javascript
原生JS简单实现ajax的方法示例
2016/11/29 Javascript
详谈js原型继承的一些问题
2017/09/06 Javascript
ES6中javascript实现函数绑定及类的事件绑定功能详解
2017/11/08 Javascript
JavaScript实现重力下落与弹性效果的方法分析
2017/12/20 Javascript
vue--点击当前增加class,其他删除class的方法
2018/09/15 Javascript
Node.js Buffer模块功能及常用方法实例分析
2019/01/05 Javascript
mock.js模拟前后台交互
2019/07/25 Javascript
JavaScript中的this基本问题实例小结
2020/03/09 Javascript
JavaScript异步操作的几种常见处理方法实例总结
2020/05/11 Javascript
Python实现多线程抓取妹子图
2015/08/08 Python
详解Python爬虫的基本写法
2016/01/08 Python
Python 3.x 安装opencv+opencv_contrib的操作方法
2018/04/02 Python
python字符串string的内置方法实例详解
2018/05/14 Python
Python对接支付宝支付自实现功能
2019/10/10 Python
50行Python代码实现视频中物体颜色识别和跟踪(必须以红色为例)
2019/11/20 Python
Python非单向递归函数如何返回全部结果
2020/12/18 Python
css3 pointer-events 介绍详解
2017/09/18 HTML / CSS
使用HTML5做个画图板的方法介绍
2013/05/03 HTML / CSS
html5的input的required使用中遇到的问题及解决方法
2018/04/24 HTML / CSS
元旦晚会邀请函
2014/02/01 职场文书
法律专业求职信
2014/05/24 职场文书
毕业生求职信范文
2014/06/29 职场文书
学校与家长安全责任书
2014/07/23 职场文书
运动会演讲稿100字
2014/08/25 职场文书
社会发展项目建议书
2014/08/25 职场文书
高中生第一学年自我鉴定
2014/09/12 职场文书
农业局党的群众路线教育实践活动整改方案
2014/09/20 职场文书
三好学生事迹材料
2014/12/24 职场文书
九年级语文教学反思
2016/03/03 职场文书
车辆挂靠协议书
2016/03/23 职场文书
如何做好工作总结!
2019/04/10 职场文书