|
麻烦大家看一下,在论坛看到一个人写的代码,照例子仿了一下
但是,怎么后边都带......请大家指导
$mdb_data_pwd=""
$mdb_data_path="data.mdb"
$mdb_name="Wizard"
$t="*"
$fanghao="1"
$zujin="120"
$yajin="50"
$dianfei="20"
$yezhu="雷锋"
$dianhua="15225155656"
$shenfenzheng="410103198205450854"
$riqi="2010-5-31"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Access 数据库", 615, 438, 192, 124)
$ListView1 = GUICtrlCreateListView("房号| 租金 | 押金 | 电费 | 业主 | 电话 | 身份证 | 日期 ", 16, 16, 577, 361)
$Button1 = GUICtrlCreateButton("创建", 16, 392, 97, 33)
$Button2 = GUICtrlCreateButton("写入", 136, 392, 97, 33)
$Button3 = GUICtrlCreateButton("删除", 256, 392, 97, 33)
$Button4 = GUICtrlCreateButton("更新", 376, 392, 97, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
data($mdb_data_path,$mdb_name)
Case $button2
sx()
Case $button4
du()
EndSwitch
WEnd
Func data($mdb_data_path, $mdb_name)
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 " & $mdb_name)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$addfld.Execute("ALTER TABLE " & $mdb_name & " ADD id identity(1, 1) primary key,fanghao char ,zujin char ,yajin int,dianfei char,yezhu char,dianhua char,shenfenzheng char,riqi char");id identity(1, 1) primary key为自动编号和主键
$addfld.Close;建列表名
MsgBox(64,"提示","建立数据库成功",5)
Else
MsgBox(64,"提示","你已经建立了一个数据库了",5)
EndIf
EndFunc
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 " & $mdb_name)
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 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 wizard (fanghao,zujin,yajin,dianfei,yezhu,dianhua,shenfenzheng,riqi) Values('"&$fanghao&"','"&$zujin&"','"&$yajin&"','"&$dianfei&"','"&$yezhu&"','"&$dianhua&"','"&$shenfenzheng&"','"&$riqi&"')")
WEnd
$addfld.close
MsgBox(4096,"完毕","成功写入数据库")
EndFunc |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|