ross_liu 2019-06-06 17:01 采纳率: 25%
浏览 472
已采纳

puthon 连接远程sqlserver数据库的时候报错【 an unknown reason】

import winsound
import xlwt
import pymssql
import tkinter as tk

window = tk.Tk()
window.title('my window')
window.geometry('300x300')
e = tk.Entry(window, show=None)
e.pack()
def set_style(name, height, bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
def write_excel(d):
f = xlwt.Workbook()
sheet1 = f.add_sheet('学生',cell_overwrite_ok=True)
row0 = ["id","username","age"]
#写第一行
for i in range(0,len(row0)):
sheet1.write(0,i,row0[i],set_style('Times New Roman',220,True))
#从第二行开始写从数据库里面捞出来的数据
for i in range(0,len(d)):
for m in range(0, len(d[i])):
sheet1.write(i + 1, m, d[i][m], set_style('Times New Roman', 220, True))
f.save('D:/'+tt+'.xls',)

global Mes1
Mes1 = None
def insert_point():
conn = pymssql.connect('host="11223";user="ddd";password=r"ddd!"";database=r"NS"')
cur = conn.cursor()
if cur:
print(1)
global tt
tt=e.get()
if e.get()=='':
show_eff(False)
else:
cur.execute("select 'OptoLux Lower Console Assembly', c.value,SUBSTRING(b.PartNumber,charindex('08',b.PartNumber),17)aa,a.ChildSerialNumber,b.Description ,a.InsertedTime,e.EnterTime from ffUnitComponent a inner join ffPart b on a.ChildPartID =b.id inner join ffSerialNumber c on a.unitid=c.UnitID inner join ffSerialNumber d on a.ChildUnitID=d.UnitID inner join ffHistory e on a.UnitID=e.UnitID where c.Value=%s and( b.PartNumber like 'KSIH-08888-1325-000-__'or b.PartNumber like 'KSIH-PCBA-08895-4019-000-__'or b.PartNumber like 'KSIH-08888-1230-000-%' or b.PartNumber like 'KSIH-08888-1010-000-%' or b.PartNumber like 'KSIH-PCBA-08895-4000-000-%'or b.PartNumber like 'KSIH-PCBA-08895-4214-000-%'or b.PartNumber like 'KSIH-PCBA-08895-4032-000-%'or b.PartNumber like 'KSIH-PCBA-08895-4305-A00-%'or b.PartNumber like 'KSIH-PCBA-08895-4166-000-%'or b.PartNumber like 'KSIH-PCBA-08895-4002-000-%'or b.PartNumber like 'KSIH-PCBA-08991-4214-000-%'or b.PartNumber like 'KSIH-PCBA-08895-4020-000-%'or b.PartNumber like 'KSIH-PCBA-08890-4272-000-%'or b.PartNumber like 'KSIH-PCBA-08890-4168-000-%'or b.PartNumber like 'KSIH-08891-1326-000-%')and e. UnitStateID=23 order by b.PartNumber desc", (e.get()))
data = cur.fetchall()
if len(data) !=0:
t = []
d = []
for i in range(len(data)):
t.append(data[i][0])
t.append(data[i][1].rstrip())
t.append(data[i][2])
d.append(t)
t = []
write_excel(d)
cur.close()
show_eff(True)
else:
show_eff(False)
def show_eff(e):
global Mes1
if Mes1 is None:
Mes1 = tk.Message(text = 'OK' if e else 'Fail', width = 60)
Mes1.pack()
else:
Mes1.pack_forget()
Mes1 = tk.Message(text = 'OK' if e else 'Fail', width = 60)
Mes1.pack()
if e==False:
winsound.Beep(900, 1000)
def windowset():
b1 = tk.Button(window, text='insert point', width=15,
height=2, command=insert_point)
b1.pack()
window.mainloop()
windowset()
图片说明

图片说明

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-06-06 17:40
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 selenium获取非固定位置的元素
  • ¥50 手写签名不能上传的问题
  • ¥30 linux odbc怎么添加gbase数据库
  • ¥20 电脑开机黑屏,只有一个鼠标,联想zj者y7000
  • ¥20 DXSDK_jun10
  • ¥20 请问这种量表怎么用spss量化分析(作为中介模型的因变量
  • ¥55 AD844 howland电流源如何驱动大额负载
  • ¥15 C++ /QT 内存权限的判断函数列举
  • ¥15 深度学习GFnet理解问题
  • ¥15 单细胞小提琴堆叠图代码