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实现在sqlite动态创建表的方法
May 08 Python
Python实现分割文件及合并文件的方法
Jul 10 Python
Python实现获取命令行输出结果的方法
Jun 10 Python
python中os和sys模块的区别与常用方法总结
Nov 14 Python
解决Pycharm界面的子窗口不见了的问题
Jan 17 Python
python3实现点餐系统
Jan 24 Python
Python分布式进程中你会遇到的问题解析
May 28 Python
Windows系统下pycharm中的pip换源
Feb 23 Python
python爬虫容易学吗
Jun 02 Python
Python读取Excel一列并计算所有对象出现次数的方法
Sep 04 Python
Python在后台自动解压各种压缩文件的实现方法
Nov 10 Python
Python读取pdf表格写入excel的方法
Jan 22 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
php中限制ip段访问、禁止ip提交表单的代码分享
2014/08/22 PHP
PHP中empty和isset对于参数结构的判断及empty()和isset()的区别
2015/11/15 PHP
PHP PDOStatement::debugDumpParams讲解
2019/01/30 PHP
编写Js代码要注意的几条规则
2010/09/10 Javascript
jquery控制listbox中项的移动并排序的实现代码
2010/09/28 Javascript
javascript四舍五入函数代码分享(保留后几位)
2013/12/10 Javascript
使用javascript实现简单的选项卡切换
2015/01/09 Javascript
jQuery实现灰蓝风格标准二级下拉菜单效果代码
2015/08/31 Javascript
解决jquery中动态新增的元素节点无法触发事件问题的两种方法
2015/10/30 Javascript
最简单纯JavaScript实现Tab标签页切换的方式(推荐)
2016/07/25 Javascript
关于Jquery中的bind(),on()绑定事件方式总结
2016/10/26 Javascript
多种方式实现js图片预览
2016/12/12 Javascript
JS实现复制内容到剪贴板功能
2017/02/05 Javascript
微信小程序开发之animation循环动画实现的让云朵飘效果
2017/07/14 Javascript
JS判断数组那点事
2017/10/10 Javascript
vue父子组件的通信方法(实例详解)
2019/11/10 Javascript
jQuery带控制按钮轮播图插件
2020/07/31 jQuery
[00:21]DOTA2亚洲邀请赛 Logo演绎
2015/02/07 DOTA
python中使用sys模板和logging模块获取行号和函数名的方法
2014/04/15 Python
python模拟Django框架实例
2016/05/17 Python
Python 备份程序代码实现
2017/03/06 Python
python指定写入文件时的编码格式方法
2018/06/07 Python
python实现字符串和字典的转换
2018/09/29 Python
python3 打印输出字典中特定的某个key的方法示例
2019/07/06 Python
Python Django form 组件动态从数据库取choices数据实例
2020/05/19 Python
Python3获取cookie常用三种方案
2020/10/05 Python
Python基于Faker假数据构造库
2020/11/30 Python
Pop In A Box英国:Funko POP搪胶公仔
2019/05/27 全球购物
影视制作岗位职责
2013/12/04 职场文书
优秀班组长事迹
2014/05/31 职场文书
医学生自荐信范文
2015/03/05 职场文书
卫生主题班会
2015/08/14 职场文书
巾帼建功标兵先进事迹材料
2016/02/29 职场文书
Mysql 性能监控及调优
2021/04/06 MySQL
教你利用Nginx 服务搭建子域环境提升二维地图加载性能的步骤
2021/09/25 Servers
利用Sharding-Jdbc进行分库分表的操作代码
2022/01/22 Java/Android