|
本帖最后由 nmgwddj 于 2010-1-22 20:13 编辑
我是用的论坛中一个数据库操作例子来修改的,想做个网吧远程工具
但是我在写入数据的时候 程序全部退出 而且数据没有写入。
下面是代码 还不完整 就是在窗口2里边 点击确定后 就出错了。请高手帮忙看下 感激不尽!
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path = "sky.mdb"
$mdb_data_pwd = ""
$name = "天生我才"
$pass = "过去"
$qq = 25359272
$e_mail = "xtybfgu@163.com"
$T = "*"
$tblname = "tywb"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("数据库操作例子", 630, 400, 193, 115)
$ListView1 = GUICtrlCreateListView(" ID | 网吧名称 | IP | 密码 | 端口 ", 8, 30, 450, 350)
$Button0 = GUICtrlCreateButton("创建数据", 500, 30, 97, 25, 0)
$Button1 = GUICtrlCreateButton("写入数据", 500, 90, 97, 25, 0)
$Button2 = GUICtrlCreateButton("更新数据", 500, 150, 97, 25, 0)
$Button3 = GUICtrlCreateButton("删除数据", 500, 210, 97, 25, 0)
$Button4 = GUICtrlCreateButton("读取数据", 500, 270, 97, 25, 0)
$Button5 = GUICtrlCreateButton("运行", 500, 330, 97, 25, 0)
$Button6 = GUICtrlCreateButton("窗口2", 500, 380, 97, 25, 0)
$Form2 = GUICreate("窗口2", 400, 100, 231, 334)
$mingcheng = GUICtrlCreateInput("网吧名称", 10, 15, 80, 20)
$IP = GUICtrlCreateInput("网吧IP", 110, 15, 80, 20)
$MIMA = GUICtrlCreateInput("连接密码", 210, 15, 80, 20)
$duankou = GUICtrlCreateInput("连接端口", 310, 15, 80, 20)
$Button7 = GUICtrlCreateButton("确定", 100, 50, 97, 25, 0)
$Button8 = GUICtrlCreateButton("取消", 200, 50, 97, 25, 0)
GUISwitch($Form1)
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()
Case $Button5 ;运行
yx()
Case $Button6 ;窗口2
ck()
Case $Button7 ;窗口2
qd()
Case $Button8 ;窗口2
qx()
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 & "|" & $RS.Fields(3).value & "|" & $RS.Fields(4).value, $ListView1)
$RS.movenext
WEnd
$RS.close
$addfld.Close
EndFunc ;==>du
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 ;==>del
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='221.202.188.62',pass='good',e_mail='25359272@qq.com' WHERE id" & " = " & $Strnspin[1]
$addfld.execute($sQuery)
$addfld.close
MsgBox(4096, "提示:", $Strnspin[1] & " 更新成功!!!")
EndFunc ;==>up
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)
$x = 0
While 1
$x += 1
If $x > 10 Then ExitLoop
$addfld.Execute("insert into tywb (name,pass,qq,e_mail) values('" & $name & "','" & $pass & "','" & $qq & "','" & $e_mail & "')")
WEnd
$addfld.close
MsgBox(4096, "提示:", " 成功写入数据库!")
EndFunc ;==>sx
Func yx()
$Strn = GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin = StringSplit($Strn, "|")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
Run("mstsc /v "&$Strnspin[2])
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 ,qq int,e_mail char")
$addfld.Close;建列表名
MsgBox(64, "提示", "建立数据库成功", 5)
Else
MsgBox(64, "提示", "你已经建立了一个数据库了", 5)
EndIf
EndFunc ;==>data
Func ck()
GUISwitch($Form2) ; 切换当前窗口到子窗口
GUISetState(@SW_SHOW)
EndFunc
Func qd()
$a=GUICtrlRead($mingcheng)
$b=GUICtrlRead($IP)
$c=GUICtrlRead($MIMA)
$d=GUICtrlRead($duankou)
MsgBox(64, "提示", GUICtrlRead($mingcheng), 5)
$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 tywb (name,pass,qq,e_mail) values('" & $a & "','" & $b & "','" & $c & "','" & $d & "')")
$addfld.Close
EndFunc
Func qx()
GUISwitch($Form2)
GUISetState(@SW_HIDE)
endfunc |
|