没有知道 发表于 2010-4-30 04:17:28

关于操作数据库的(已解决)

本帖最后由 没有知道 于 2010-7-27 16:43 编辑

请教一下怎么删除一条被选中的记录,下面的del()用在别的数据库可以,但是用载远古ACC的就不行,望高手们指点,数据库是远古刚装出来的#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path="data.mdb";数据库名
$mdb_data_pwd="viewgood" ;数据库密码
$tblname="TypeInfo";表
$ziduan="TypeName"
$T="*"

$tatle1 = IniRead("data.ini", "标题", "标题1", "未知")
$tatle2 = IniRead("data.ini", "标题", "标题2", "未知")
$A1 = IniRead("data.ini", "data", "分类1", "未知")
$A2 = IniRead("data.ini", "data", "分类2", "未知")
$A3 = IniRead("data.ini", "data", "分类3", "未知")
$A4 = IniRead("data.ini", "data", "分类4", "未知")
$A5 = IniRead("data.ini", "data", "分类5", "未知")
$A6 = IniRead("data.ini", "data", "分类6", "未知")
$A7 = IniRead("data.ini", "data", "分类7", "未知")
$A8 = IniRead("data.ini", "data", "分类8", "未知")
$A9 = IniRead("data.ini", "data", "分类9", "未知")
$A10 = IniRead("data.ini", "data", "分类10", "未知")
$A11 = IniRead("data.ini", "data", "分类11", "未知")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("网吧管理", 700, 430, 193, 100)
$ListView1 = GUICtrlCreateListView("   ID|      1|    2|    3    |    4   |      5   |       6   |   7    ", 8, 100, 680, 321, -1 );,$LVS_EX_GRIDLINES
$Button1 = GUICtrlCreateButton("读取", 24, 60, 75, 25, 0)
$Button2 = GUICtrlCreateButton("写入", 120, 60, 75, 25, 0)
$Button3 = GUICtrlCreateButton("删除", 220, 60, 75, 25, 0)
$Button4 = GUICtrlCreateButton("刷新", 320, 60, 75, 25, 0)
$Label1 = GUICtrlCreateLabel($tatle1&@CRLF&$tatle2, 8, 8, 609, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                          du()
                          
                Case $Button2               
                          sr()
                Case $Button3
                          del()
                Case $Button4
                          up()
                          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 "&$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
                           MsgBox(0,"","已打开"&$mdb_data_path&"数据库")
EndFunc
                  
Func sr()
         $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 TypeInfo (TypeName) values('"&$A1&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A2&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A3&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A4&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A5&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A6&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A7&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A8&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A9&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A10&"')")
               $addfld.Execute("insert into TypeInfo (TypeName) values('"&$A11&"')")
         $addfld.close
         MsgBox(4096, "提示:"," 成功写入数据库!")
       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 & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
            $sQuery = ("DELETE FROM " & $tblname & " IN '" & $mdb_data_path & "' WHERE id" & " = " & $Strnspin)
            MsgBox(0,"",$sQuery)
                        $addfld.execute($sQuery)
                        $addfld.execute($sQuery)
            $addfld.close
MsgBox(4096, "提示:",$Strnspin&"    删除成功!!!")

EndFunc

没有知道 发表于 2010-7-27 16:07:04

这个问题我已经解决了{:face (411):}
页: [1]
查看完整版本: 关于操作数据库的(已解决)