|
发表于 2012-10-16 09:16:12
|
显示全部楼层
应该是这样吧
Dim $list[10],$RS1[4],$tabitem[5]
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
#include <GUIListView.au3>
Global $j
$mdb_data_path=@ScriptDir&"\DB0.mdb"
$mdb_data_pwd="1"
$tblname="测试"
$tb=GUICreate("学习",300,250)
$ok=GUICtrlCreateButton("创建",5,5,50,50)
$du=GUICtrlCreateButton("读取",5,60,50,50)
du();读取显示
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
;Case $du
;du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
GUICtrlSetData($tblname, 'name', 'name')
If FileExists($mdb_data_path) Then
MsgBox(64, "提示", "数据库已创建!")
Else
$newMdb = ObjCreate('ADOX.Catalog')
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$newmdb.ActiveConnection.Close;建数据
$addtbl = ObjCreate("ADODB.Connection")
$addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addTbl.Execute("CREATE TABLE " & $tblname)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addfld.Execute("ALTER TABLE " & $tblname & " ADD name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into "&$tblname&" (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
MsgBox(64, "提示", "创建成功!!")
EndIf
EndFunc
Func du(); 读取数据库;;
$i=0
$tab=GUICtrlCreateTab(60,10,220,20)
GUICtrlSendMsg($List, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path& ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$RS =ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open ("Select * From "&$tblname )
while Not $RS.eof And Not $RS.bof
if @error =1 Then ExitLoop
$i=$i+1
GUICtrlCreateTabItem($RS.Fields(0).value )
$list[$i]=GUICtrlCreateList($RS.Fields(0).value& "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value,62,35,220,200, $LVS_EX_TRACKSELECT)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc
但是这样如何编辑??
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <TabConstants.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
$mdb_data_path = @ScriptDir & "\DB0.mdb"
$mdb_data_pwd = "1"
$tblname = "测试"
$tb = GUICreate("学习", 300, 250)
$ok = GUICtrlCreateButton("创建", 5, 5, 50, 50)
$du = GUICtrlCreateButton("读取", 5, 60, 50, 50)
$Tab1 = GUICtrlCreateTab(60, 0, 220, 20)
$TabSheet1 = GUICtrlCreateTabItem("1")
$ListView1 = GUICtrlCreateListView("姓名|性别|QQ", 60, 25, 220, 200, $LVS_REPORT, $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor(-1, 0xC0C0C0); 背景色
GUICtrlSetFont(-1, 10, 400, 0, "微软雅黑")
;GUICtrlSetColor(-1, 0x0000FF)
_GUICtrlListView_SetColumn($ListView1, 0, "姓名", 60, 2)
_GUICtrlListView_SetColumn($ListView1, 1, "性别", 60, 2)
_GUICtrlListView_SetColumn($ListView1, 2, "QQ", 80, 2)
$hImage = _GUIImageList_Create(1, 18);30为每行的间距(即网格高度)
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
du();读取显示
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ok
jian();创建数据库
Case $du
du(); 读取数据库
EndSwitch
WEnd
Func jian();创建数据库
GUICtrlSetData($tblname, 'name', 'name')
If FileExists($mdb_data_path) Then
MsgBox(64, "提示", "数据库已创建!")
Else
$newMdb = ObjCreate('ADOX.Catalog')
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$newMdb.ActiveConnection.Close;建数据
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addtbl.Execute("CREATE TABLE " & $tblname)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$addfld.Execute("ALTER TABLE " & $tblname & " ADD name text(255) ,ssex text(50),qq text(50)")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊二','男','11111')")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊一','男','122221')")
$addfld.Execute("insert into " & $tblname & " (name,ssex,qq) values('啊三','女','122431')")
$addfld.Close;建列表名
MsgBox(64, "提示", "创建成功!!")
EndIf
EndFunc ;==>jian
Func du(); 读取数据库;;
GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select * From " & $tblname)
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value, $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc ;==>du |
|