python数据库编程 ODBC方式实现通讯录
作者:Ugex 发布时间:2024-01-15 10:58:01
标签:python,ODBC,通讯录
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()
来源:https://blog.csdn.net/Ugex_Savelar/article/details/103056839
0
投稿
猜你喜欢
- 简介滚动条小部件用于向下滚顶其他小部件的内容,如列表框,文本和画布,但是,我们也可以为Entry小部件创建水平滚动条,常常被用于实现文本,画
- 首先如果柱状图中有中文,比如X轴和Y轴标签需要写中文,解决中文无法识别和乱码的情况,加下面这行代码就可以解决了:plt.rcParams[&
- 查询到效率低的 SQL 语句 后,可以通过 EXPLAIN 或者 DESC 命令获取 MySQL 如何执行 SELECT 语句的信息,包括在
- 先上代码:import tensorflow as tfx = tf.ones(shape=[100, 200], dtype=tf.int
- Python 模块EasyGui详细介绍前言:在Windows想用Python开发一些简单的界面,所以找到了很容易上手的EasyGui库。下
- 本文实例讲述了Python基于TCP实现会聊天的小机器人功能。分享给大家供大家参考,具体如下:一 代码1、服务端程序import socke
- asp学习入门经验介绍,本文初步介绍了初学asp的一些相关知识,如VBScript语法简介,循环控制语句的使用,asp数据库的简单操作查询,
- import模块时有错误红线的解决 前情提要概念:在一个文件中代码越长越不容易维护,为了编写可维护的代码,我们把很多函数分组,分别
- 使用ASP设置指定站点CPU最大使用程度'=============================================
- 方法一:1、进入项目目录下,运行下面程序:nohup python manage.py runserver 0.0.0.0:5008 &am
- 原则一:注意WHERE子句中的连接顺序: ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE
- 我们在上传大文件时,可能会由于服务器的原因导致文件上传失败,文件过大时由于服务器的配置或响应事件过长导致上传文件失败,这时候我们可以将一个大
- 内容摘要:本文介绍了使用CSS结合javascript来实现对超链接的类型进行标注,让浏览者明确是zip,doc,pdf或其它格式的文件。这
- innodb这种引擎,与MYISAM引擎的区别很大。特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享
- 今日一同时问我,new Date(Date(str))这段代码什么意思?我一看就晕了,一个new Date 一个Date这是什么意思?这函数
- 这里首先给出来我很早之前写的一篇博客,Python实现去除列表中重复元素的方法小结【4种方法】,感兴趣的话可以去看看,今天是在实践过程中又积
- 错误信息UnicodeDecodeError: ‘utf-8' codec can't decode byte 0xce i
- CKEditor官方演示是有上传图片和浏览服务器文件功能的,但是我们自己下载回来的却没有这两个功能…… 其实还需要下载另外一个组件:CKFi
- 1.open使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。fi
- Python实现OCR识别:pytesseractPython常用pytesseract进行图片上的文字识别,即OCR识别,完整的代码比较简