|
这个是把 要FileOpenDialog选择的 图片路径 存入数据库 但是老出错 不知道什么问题! 请问各位高手帮忙看看
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path="sy.mdb"
$mdb_data_pwd=""
$name="数据"
$pass="不知道"
$qq="00987342"
$XP=""
$T="*"
$tblname="tywb"
$Form1 = GUICreate("数据库操作例子", 633, 454, 193, 115)
$ListView1 = GUICtrlCreateListView(" ID | 姓名 | 密码 | QQ | 照片 ", 300, 24, 300, 361)
$Button1 = GUICtrlCreateButton("写入数据", 130, 408, 130, 25, 0)
$XP_Input = GUICtrlCreateInput("", 70, 32, 162, 21)
GUICtrlSetState($XP_Input, $GUI_DISABLE);使控件不可用
$Label1 = GUICtrlCreateLabel("图片路径:", 14, 35, 56, 17)
$From2_xp_Button = GUICtrlCreateButton("浏览", 230, 32, 50, 22, 0)
if not FileExists($mdb_data_path) Then
data($mdb_data_path, $tblname)
Else
du()
EndIf
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $From2_xp_Button
_xp()
Case $Button1;写入
sx()
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&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value,$ListView1 )
$rs.movenext
WEnd
$rs.close
$addfld.Close
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 tywb (name,pass,qq,xp) values('"&$name&"','"&$pass&"','"&$qq&"','"&$XP&"')")
$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 ,qq int,xp char")
$addfld.Close;建列表名
Else
MsgBox(64,"提示","你已经建立了一个数据库了",5)
EndIf
EndFunc
Func _xp()
$var = FileOpenDialog("选择", "C:\Windows\", "图片文件(*.jpg)", 1 + 4 )
GUICtrlSetData($xp_Input,$var)
$XP=$var
EndFunc |
|