本帖最后由 pizigao 于 2010-3-31 14:57 编辑 #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$datename = @ScriptDir & "\data.mdb"
$mdb_data_path = @ScriptDir & "\data.mdb"
If not FileExists($datename) then Exit (Msgbox(16,'错误','未找到DATA.MDB文件,请检查文件名和路径'))
$mdb_data_pwd = "123456"
$tblname = "user"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("批量删除员工信息", 633, 454, 193, 115)
$ListView1 = GUICtrlCreateListView(" ID | 工号 | 证照号码 | 姓 名 ", 8, 24, 617, 361)
$Button3 = GUICtrlCreateButton("删除数据",510, 408, 113, 25, 0)
$Button4 = GUICtrlCreateButton("读取数据", 280, 408, 113, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;du()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button3 ;删除
del()
du()
Case $Button4 ;读取
du()
EndSwitch
WEnd
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 user" )
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&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value,$ListView1 )
; MsgBox(0, "", $RS.Fields (1).value);显示表第一个数据
$rs.movenext
WEnd
$rs.close
$addfld.Close
EndFunc
Func del()
$Strn=GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin=StringSplit($Strn,"|")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path)
$sQuery ="DELETE FROM " & $tblname & " IN '" & $mdb_data_path & "' WHERE id" & " = " & $Strnspin[1]
; MsgBox(0,"",$sQuery)
$addfld.execute($sQuery)
$addfld.close
MsgBox(4096, "提示:",$Strnspin[1]&" 删除成功!!!")
EndFunc
|