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

作者:Ugex 时间:2024-01-15 10:58:01 

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

标签:python,ODBC,通讯录
0
投稿

猜你喜欢

  • ASP获取当前页面URL地址(带参数)的方法

    2010-01-14 19:40:00
  • 用ASP显示ACCESS数据库的GIF图象

    2008-11-16 18:09:00
  • django上传图片并生成缩略图方法示例

    2022-08-12 01:45:53
  • python爬虫爬取快手视频多线程下载功能

    2021-10-29 09:24:04
  • Python实现密钥密码(加解密)实例详解

    2022-09-10 12:03:37
  • js获取指定字符前/后的字符串简单实例

    2024-05-02 17:31:10
  • 懒就要懒到底——鼠标自动点击(含时间判断)

    2024-04-22 22:18:06
  • python批量查询、汉字去重处理CSV文件

    2023-01-20 08:27:17
  • python结合shell自动创建kafka的连接器实战教程

    2023-01-06 19:17:13
  • python四个坐标点对图片区域最小外接矩形进行裁剪

    2022-01-18 02:18:09
  • mysql8.0主从复制搭建与配置方案

    2024-01-15 11:26:25
  • Go语言的Windows下环境配置以及简单的程序结构讲解

    2023-08-26 16:04:10
  • Pytorch 之修改Tensor部分值方式

    2023-04-11 06:45:12
  • Mysql聚合函数的使用介绍

    2024-01-14 03:50:34
  • pandas进行时间数据的转换和计算时间差并提取年月日

    2021-03-14 02:22:22
  • 简单介绍MySQL中索引的使用方法

    2024-01-15 07:04:50
  • Vue计时器的用法详解

    2024-04-28 09:28:51
  • bitbucket搭建详细过程记录

    2023-08-25 23:52:31
  • Select 控件Combox加强版(IE Only)

    2008-07-23 13:26:00
  • 使用Javascript动态增加,删除表格

    2008-02-03 19:15:00
  • asp之家 网络编程 m.aspxhome.com