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中apply函数的用法实例教程
Jul 31 Python
python利用urllib实现爬取京东网站商品图片的爬虫实例
Aug 24 Python
浅谈python 读excel数值为浮点型的问题
Dec 25 Python
利用python和ffmpeg 批量将其他图片转换为.yuv格式的方法
Jan 08 Python
Django REST framework视图的用法
Jan 16 Python
详解Python爬取并下载《电影天堂》3千多部电影
Apr 26 Python
django框架auth模块用法实例详解
Dec 10 Python
python爬虫学习笔记之pyquery模块基本用法详解
Apr 09 Python
基于Python正确读取资源文件
Sep 14 Python
利用Python过滤相似文本的简单方法示例
Feb 03 Python
python 对xml解析的示例
Feb 27 Python
python 实现体质指数BMI计算
May 26 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中用正则表达式清除字符串的空白
2011/01/17 PHP
PHP句法规则详解 入门学习
2011/11/09 PHP
PHP中is_file不能替代file_exists的理由
2014/03/04 PHP
PHP实现XML与数据格式进行转换类实例
2015/07/29 PHP
TNC vs BOOM BO3 第一场2.13
2021/03/10 DOTA
jQuery Div中加载其他页面的实现代码
2009/02/27 Javascript
理解Javascript_03_javascript全局观
2010/10/11 Javascript
js对象数组按属性快速排序
2011/01/31 Javascript
javascript学习笔记(七)利用javascript来创建和存储cookie
2011/04/08 Javascript
jQuery基础语法实例入门
2014/12/23 Javascript
js实现从中间开始往上下展开网页窗口的方法
2015/03/02 Javascript
JavaScript实现打字效果的方法
2015/07/10 Javascript
Js查找字符串中出现次数最多的字符及个数实例解析
2016/09/05 Javascript
浅谈EasyUI常用控件的禁用方法
2016/11/09 Javascript
原生js实现放大镜效果
2017/01/11 Javascript
canvas绘制表盘时钟
2017/01/23 Javascript
jQuery代码实现实时获取时间
2017/01/29 Javascript
详解webpack打包vue时提取css
2017/05/26 Javascript
浅析JavaScript中的平稳退化(graceful degradation)
2017/07/24 Javascript
Javascript刷新页面的实例
2017/09/23 Javascript
基于jquery.page.js实现分页效果
2018/01/01 jQuery
Layui 数据表格批量删除和多条件搜索的实例
2019/09/04 Javascript
JQuery 实现文件下载的常用方法分析
2019/10/29 jQuery
[01:03:22]LGD vs OG 2018国际邀请赛淘汰赛BO3 第一场 8.25
2018/08/29 DOTA
python从入门到精通(DAY 1)
2015/12/20 Python
python实现定时提取实时日志程序
2018/06/22 Python
python GUI编程(Tkinter) 创建子窗口及在窗口上用图片绘图实例
2020/03/04 Python
澳大利亚女士时装在线:Rockmans
2018/09/26 全球购物
zooplus波兰:在线宠物店
2019/07/21 全球购物
荷兰音乐会和音乐剧门票订购网站:Topticketshop
2019/08/27 全球购物
Dr. Martens马汀博士法国官网:马丁靴鼻祖
2020/01/15 全球购物
C#实现对任一张表的数据进行增,删,改,查要求,运用Webservice,体现出三层架构
2014/07/11 面试题
自荐信格式写作方法有哪些呢
2013/11/20 职场文书
公司酒会主持词
2015/07/02 职场文书
pytorch 如何使用batch训练lstm网络
2021/05/28 Python
使用Python通过企业微信应用给企业成员发消息
2022/04/18 Python