曾经做过的一个Python小程序,读取ACCESS数据库,然后list数据
# -*- coding: cp936 -*-
import wx
import wx.lib
import sys,glob,random
import win32com.client
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
class DemoFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,u"安全检查",size=(800,600))
def adddate():
conn = win32com.client.Dispatch(r‘ADODB.Connection‘)
DSN = ‘PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=yb.mdb;‘
conn.Open(DSN)
rs = win32com.client.Dispatch(r‘ADODB.Recordset‘)
rs_name =‘aqjc‘
rs.Open(‘[‘+rs_name+‘]‘,conn,1,3)
if rs.recordcount==0:
sys.exit()
self.list.InsertColumn(0,u‘备注‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘发现问题‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘时段‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘时间‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘岗位‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘日期‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
self.list.InsertColumn(0,u‘id‘,format=wx.LIST_FORMAT_CENTRE, width=-1)
while not rs.EOF:
index = self.list.InsertStringItem(sys.maxint,str(rs.Fields.Item(0).value))
self.list.SetStringItem(index,1,str(rs.Fields.Item(1).value))
self.list.SetStringItem(index,2,str(rs.Fields.Item(2).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,3,str(rs.Fields.Item(3).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,4,str(rs.Fields.Item(4).value))
self.list.SetStringItem(index,5,str(rs.Fields.Item(5).value).decode(‘utf-8‘).encode(‘gbk‘))
self.list.SetStringItem(index,6,str(rs.Fields.Item(6).value).decode(‘utf-8‘).encode(‘gbk‘))
rs.MoveNext()
rs.Close()
conn.Close()
hbox = wx.BoxSizer(wx.HORIZONTAL)
panel = wx.Panel(self,-1)
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT,size=(800,600))
self.list.SetSingleStyle(wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES,True,)
hbox.Add(self.list,1,1)
panel.SetSizer(hbox)
self.Centre()
adddate()
app = wx.PySimpleApp()
frame = DemoFrame()
frame.Show()
app.MainLoop()
Python小程序,读取ACCESS数据库,然后list数据,布布扣,bubuko.com
Python小程序,读取ACCESS数据库,然后list数据
原文:http://www.cnblogs.com/liumumu2014/p/3904289.html