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实现划词翻译
Apr 23 Python
详解Python命令行解析工具Argparse
Apr 20 Python
举例讲解Python面向对象编程中类的继承
Jun 17 Python
Python结巴中文分词工具使用过程中遇到的问题及解决方法
Apr 15 Python
numpy matrix和array的乘和加实例
Jun 28 Python
Python中几种属性访问的区别与用法详解
Oct 10 Python
python实现旋转和水平翻转的方法
Oct 25 Python
解决pandas .to_excel不覆盖已有sheet的问题
Dec 10 Python
在python中按照特定顺序访问字典的方法详解
Dec 14 Python
python字符串的拼接方法总结
Nov 18 Python
python对Excel的读取的示例代码
Feb 14 Python
python判断变量是否为列表的方法
Sep 17 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
destoon安装出现Internal Server Error的解决方法
2014/06/21 PHP
ThinkPHP的常用配置选项汇总
2016/03/24 PHP
TP3.2.3框架文件上传操作实例详解
2020/01/23 PHP
jquery 全局AJAX事件使用代码
2010/11/05 Javascript
JavaScript基础篇之变量作用域、传值、传址的简单介绍与实例
2013/06/29 Javascript
jquery创建表格(自动增加表格)代码分享
2013/12/25 Javascript
bootstrap table分页模板和获取表中的ID方法
2017/01/10 Javascript
基于JavaScript实现微信抢红包功能
2017/07/20 Javascript
JavaScript实现一个简易的计算器实例代码
2018/05/10 Javascript
JS实现监控微信小程序的原理
2018/06/15 Javascript
[42:39]老党炸弹人试玩视频
2014/09/03 DOTA
[01:01:18]VP vs NIP 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/17 DOTA
[47:43]完美世界DOTA2联赛PWL S3 Magama vs GXR 第二场 12.19
2020/12/24 DOTA
Python 除法小技巧
2008/09/06 Python
图文讲解选择排序算法的原理及在Python中的实现
2016/05/04 Python
轻量级的Web框架Flask 中模块化应用的实现
2017/09/11 Python
Python利用lxml模块爬取豆瓣读书排行榜的方法与分析
2019/04/15 Python
详解python 爬取12306验证码
2019/05/10 Python
python腾讯语音合成实现过程解析
2019/08/01 Python
Django框架 信号调度原理解析
2019/09/04 Python
解决Opencv+Python cv2.imshow闪退问题
2020/04/24 Python
Python 为什么推荐蛇形命名法原因浅析
2020/06/18 Python
python实现数据结构中双向循环链表操作的示例
2020/10/09 Python
学习委员自我鉴定
2014/01/13 职场文书
优秀民警事迹材料
2014/01/29 职场文书
食品安全检查制度
2014/02/03 职场文书
外联部演讲稿
2014/05/24 职场文书
党的群众路线对照检查材料(个人)
2014/09/24 职场文书
个人四风问题对照检查材料思想汇报
2014/10/06 职场文书
村党的群众路线教育实践活动总结材料
2014/10/31 职场文书
2015年度电厂个人工作总结
2015/05/13 职场文书
隐形的翅膀观后感
2015/06/10 职场文书
团支部书记竞选稿
2015/11/21 职场文书
教您怎么制定西餐厅运营方案 ?
2019/07/05 职场文书
高中优秀作文(范文)
2019/08/15 职场文书
td 内容自动换行 table表格td设置宽度后文字太多自动换行
2022/12/24 HTML / CSS