|
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
Opt('MustDeclareVars', 1)
Global $GuiWinIns
Global $GuiEdtOutput, $GuiEdtInput, $GuiBtnGo
Global $objConn, $objRS
Global $sDatabase = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\TryDB\db.mdb"
Global $sInfo = ""
_Main()
Exit
Func _Main()
_CreateWin()
$objConn = ObjCreate("ADODB.Connection")
$objRS = ObjCreate("ADODB.Recordset")
$objConn.Open($sDatabase)
$objRS.ActiveConnection = $objConn
While True
Sleep(100)
WEnd
EndFunc
Func _CreateWin()
$GuiWinIns = GUICreate("TryDB", 500, 400, -1, -1, -1, $WS_EX_APPWINDOW)
$GuiEdtOutput = GUICtrlCreateEdit("", 20, 20, 460, 300, BitOR($ES_READONLY, $ES_MULTILINE, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL))
$GuiEdtInput = GUICtrlCreateEdit("", 20, 340, 350, 22, $ES_AUTOHSCROLL)
$GuiBtnGo = GUICtrlCreateButton("Go", 380, 339, 100, 25, BitOR($BS_CENTER, $BS_DEFPUSHBUTTON, $BS_VCENTER))
; ============================================================================================
GUISetOnEvent($GUI_EVENT_CLOSE, "_MsgOnExit")
GUICtrlSetOnEvent($GuiBtnGo, "_MsgOnOk")
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
GUISetState(@SW_SHOW, $GuiWinIns)
EndFunc
Func _MsgOnExit()
$objConn.Close
Exit
EndFunc
Func _MsgOnOk()
Local $sSQL = GUICtrlRead($GuiEdtInput)
Local $sTmp = ""
Local $i
If $sSQL <> "" Then
$objRS.open($sSQL)
$sInfo = $sInfo & "Count = " & $objRS.Fields.count & @CRLF
While Not $objRS.eof
For $i = 0 To $objRS.Fields.count - 1
$sInfo = $sInfo & $objRS.Fields($i).value & " "
Next
$sInfo = $sInfo & @CRLF
$objRS.movenext
WEnd
$sInfo = $sInfo & @CRLF
$objRS.Close
GUICtrlSetData($GuiEdtOutput, $sInfo)
EndIf
GUICtrlSetData($GuiEdtInput, "")
GUICtrlSetState($GuiEdtInput, $GUI_FOCUS)
EndFunc
上述代码是读取数据库的信息,而且本人试过,也能update,insert和其他操作,但是就是怎么也不不能删除数据,所以发出来请高手帮忙,别见笑哦~~~ |
|