你好:

     感谢你访问我的 Blog ,本博客只提供博主的技术经验分享,你可以在此做简单的留言和评论,我会抽空回复你;若是要深入交流探讨,请联系QQ:47853253或者加QQ群:12012081


 

【au3】脚本MDB数据库操作【万象IP收集数据库】测试用,请使用以前的AUTOIT3版本

 #include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path="sky.mdb"
$mdb_data_pwd=""
$name="IP"
$pass="加密"
$T="*"
$tblname="万象"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("万象IP加密", 633, 454, 193, 115)
$ListView1 = GUICtrlCreateListView("   ID  |      IP  |    加密  |", 8, 24, 617, 361)
$Button0 = GUICtrlCreateButton("创建新库", 20, 408, 97, 25, 0)
$Button1 = GUICtrlCreateButton("写入数据", 130, 408, 130, 25, 0)
$Button2 = GUICtrlCreateButton("更新数据", 400, 408, 97, 25, 0)
$Button3 = GUICtrlCreateButton("删除数据",510, 408, 113, 25, 0)
$Button4 = GUICtrlCreateButton("读取数据", 280, 408, 113, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
Exit
         Case  $Button0
            data($mdb_data_path, $tblname)
         Case  $Button1;写入
                   sx()
                   du();相当于刷新数据
        Case $Button2 ;更新
                   up()
                   du()
 
    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)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select "&$T & " 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
 
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] 
           $addfld.execute($sQuery)
           $addfld.close
 MsgBox(4096, "提示:",$Strnspin[1]&"    删除成功!!")
 
EndFunc
 
 
Func up()
         $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 ="update " & $tblname & " set  name='IP',pass='加密' Where id" & " = " & $Strnspin[1] 
           $addfld.execute($sQuery)
           $addfld.close
    MsgBox(4096, "提示:",$Strnspin[1]&"    更新成功!!!")
EndFunc
 
 
Func sx()
         $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("insert into 万象 (name,pass) values('"&$name&"','"&$pass&"')")
          $addfld.close
         MsgBox(4096, "提示:"," 成功写入数据库!")  
EndFunc
 
Func data($mdb_data_path, $tblname)
if not FileExists($mdb_data_path) Then
$newMdb = ObjCreate("ADOX.Catalog")
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$newmdb.ActiveConnection.Close;建数据库
$addtbl = ObjCreate("ADODB.Connection")
$addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addTbl.Execute("Create TABLE " & $tblname)
$addtbl.Close;建表
 
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld.Execute("Alter TABLE " & $tblname & " ADD id identity(1, 1) primary key,name char ,pass char");id identity(1, 1) primary key为自动编号和主键
$addfld.Close;建列表名
MsgBox(64,"提示","建立数据库成功。",5)
Else
MsgBox(64,"提示","你已经建立了一个数据库了。",5)
EndIf
EndFunc
 
 
————————————————————————————
 
 
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path="sky.mdb"
$mdb_data_pwd=""
$name="IP"
$pass="加密"
$T="*"
$tblname="万象"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("万象IP加密", 633, 454, 193, 115)
$ListView1 = GUICtrlCreateListView("   ID  |      IP  |    加密  |", 8, 24, 617, 361)
$Button0 = GUICtrlCreateButton("创建新库", 20, 408, 97, 25, 0)
$Button1 = GUICtrlCreateButton("写入数据", 130, 408, 130, 25, 0)
$Button2 = GUICtrlCreateButton("更新数据", 400, 408, 97, 25, 0)
$Button3 = GUICtrlCreateButton("删除数据",510, 408, 113, 25, 0)
$Button4 = GUICtrlCreateButton("读取数据", 280, 408, 113, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
Exit
         Case  $Button0
            data($mdb_data_path, $tblname)
         Case  $Button1;写入
                   sx()
                   du();相当于刷新数据
        Case $Button2 ;更新
                   up()
                   du()
 
    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)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select "&$T & " 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
 
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] 
           $addfld.execute($sQuery)
           $addfld.close
 MsgBox(4096, "提示:",$Strnspin[1]&"    删除成功!!")
 
EndFunc
 
 
Func up()
         $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 ="update " & $tblname & " set  name='IP',pass='加密' Where id" & " = " & $Strnspin[1] 
           $addfld.execute($sQuery)
           $addfld.close
    MsgBox(4096, "提示:",$Strnspin[1]&"    更新成功!!!")
EndFunc
 
 
Func sx()
         $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("insert into 万象 (name,pass) values('"&$name&"','"&$pass&"')")
          $addfld.close
         MsgBox(4096, "提示:"," 成功写入数据库!")  
EndFunc
 
Func data($mdb_data_path, $tblname)
if not FileExists($mdb_data_path) Then
$newMdb = ObjCreate("ADOX.Catalog")
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$newmdb.ActiveConnection.Close;建数据库
$addtbl = ObjCreate("ADODB.Connection")
$addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addTbl.Execute("Create TABLE " & $tblname)
$addtbl.Close;建表
 
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld.Execute("Alter TABLE " & $tblname & " ADD id identity(1, 1) primary key,name char ,pass char");id identity(1, 1) primary key为自动编号和主键
$addfld.Close;建列表名
MsgBox(64,"提示","建立数据库成功。",5)
Else
MsgBox(64,"提示","你已经建立了一个数据库了。",5)
EndIf
EndFunc


[本日志由 lq3447 于 2017-05-25 10:48 AM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: 163
发表评论
你没有权限发表留言!