|
各位大侠:
我在初学AU3,前一阵子用了本论坛一个大侠的源码,可以创建ACCESS数据库,也可以插入、读取、删除记录。
但我发现有一个问题,在插入记录后,读取记录,发现每条记录中莫名其妙的出现很多的"....."不知道是什么原因,愿高手相助。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path="sky.mdb"
$mdb_data_pwd=""
$name="周裕"
$pass="过去"
$qq=49703878
$xiaofei="0"
$T="*"
$tblname="tywb"
dim $file0,$file1,$file2,$file3,$file00,$file01,$file02,$file03,$file04
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("豪柏国际休闲中心", 720, 454, 193, 115)
$ListView1 = GUICtrlCreateListView(" ID | 姓名 | 账号 | 消费金额 | 剩余金额 | 发生日期", 8, 24, 800, 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);280, 408, 113, 25, 0)
$Button4 = GUICtrlCreateButton("读取数据", 280, 408, 113, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;du()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button0
data($mdb_data_path, $tblname)
Case $Button1;写入
insertform()
;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&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value&"|"& $RS.Fields (5).value,$ListView1 )
; MsgBox(0, "", $RS.Fields (1).value);显示表第一个数据
$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]
; MsgBox(0,"",$sQuery)
$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='小黑Sky',pass='good',xiaofei='25359272@qq.com' WHERE id" & " = " & $Strnspin[1]
; MsgBox(0,"",$sQuery)
$addfld.execute($sQuery)
$addfld.close
MsgBox(4096, "提示:",$Strnspin[1]&" 更新成功!!!")
EndFunc
Func insertform()
$newform=GUICreate("插入数据",633, 454, 193, 115)
;$ListView1 = GUICtrlCreateListView(" ID | 姓名 | 账号 | 消费金额 | 剩余金额 ", 8, 24, 617, 361)
$file0 = GUICtrlCreateInput("姓名", 10, 30, 40, 20)
GUICtrlSetColor(-1,0x989898)
$file1 = GUICtrlCreateInput("账号", 60, 30, 100, 20,0x2000)
$file2 = GUICtrlCreateInput("消费金额", 170, 30, 80, 20,0x2000)
$file3 = GUICtrlCreateInput("剩余金额", 260, 30, 80, 20,0x2000)
$Button_1 = GUICtrlCreateButton("提交消费记录", 350, 28, 100)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button_1
$file00=GUICtrlRead($file0)
$file01=GUICtrlRead($file1)
$file02=GUICtrlRead($file2)
$file03=GUICtrlRead($file3)
$file04=@YEAR&@MON&@MDAY&@HOUR&@MIN
insertformok()
EndSwitch
WEnd
EndFunc
Func insertformok()
MsgBox(4096,"提示",$file04)
$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,xiaofei) values('"&$file00&"','"&$file01&"','"&$file02&"','"&$file03&"')")
$addfld.Execute("insert into tywb (name,pass,qq,xiaofei,happentime) values('"&$file00&"','"&$file01&"','"&$file02&"','"&$file03&"','"&$file04&"')")
$addfld.close
MsgBox(4096,"提示","插入数据成功!")
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)
$x=0
While 1
$x+=1
if $x >1000 Then ExitLoop
$addfld.Execute("insert into tywb (name,pass,qq,xiaofei) values('"&$name&"','"&$pass&"','"&$qq&"','"&$xiaofei&"')")
WEnd
; $conn.Execute("insert into tywb (name,pass,qq,xiaofei) values('"&$name&"','"&$pass&"','"&$qq&"','"&$xiaofei&"')")
; $RS.close
$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,xiaofei int ,happentime string");id identity(1, 1) primary key为自动编号和主键
$addfld.Close;建列表名
MsgBox(64,"提示","建立数据库成功",5)
Else
MsgBox(64,"提示","你已经建立了一个数据库了",5)
EndIf
EndFunc |
|