|
楼主 |
发表于 2010-8-26 08:35:03
|
显示全部楼层
本帖最后由 sky_huir 于 2010-8-26 08:37 编辑
請問各位大大,一個數據表中共有12列,每列均賦值為A,怎么才能單獨修改某一列的值呢?
sky_huir 发表于 2010-8-26 08:20
例如如下的數據庫表:
1 TP LED EZKEY BT WLAN MODEM CAM LCDCRT HDMI ODD USB SPEAKER
1 A A A A A A A A A A A A
根據$CmdLine[1],將$FLD設置為對應的列名,然后單獨將 對應的$FLD列的值修改為$CmdLine[1]。還請各位大蝦幫幫小弟,感激涕零!!!
代碼如下:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
$mdb_data_path="db1.mdb"
$mdb_data_pwd=""
$T="T"
$TP="A"
$LED="A"
$EZKEY="A"
$BT="A"
$WLAN="A"
$MODEM="A"
$CAM="A"
$LCDCRT="A"
$HDMI="A"
$ODD="A"
$USB="A"
$SPEAKER="A"
$tblname="Sheet1"
IF $CmdLine[0] = "" Then
;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 1 identity(1, 1) primary key,TP VARCHAR,LED VARCHAR,EZKEY VARCHAR,BT VARCHAR,WLAN VARCHAR,MODEM VARCHAR,CAM VARCHAR ,LCDCRT VARCHAR ,HDMI VARCHAR,ODD VARCHAR,USB VARCHAR,SPEAKER VARCHAR,T VARCHAR")
$addfld.Execute("insert into Sheet1 (TP,LED,EZKEY,BT,WLAN,MODEM,CAM,LCDCRT,HDMI,ODD,USB,SPEAKER,T) values('"&$TP&"','"&$LED&"','"&$EZKEY&"','"&$BT&"','"&$WLAN&"','"&$MODEM&"','"&$CAM&"','"&$LCDCRT&"','"&$HDMI&"','"&$ODD&"','"&$USB&"','"&$SPEAKER&"','"&$T&"')")
$addfld.Close
MsgBox(64,"提示","建立數據庫成功",1)
Else
_update()
EndIf
Exit
;EndFunc
Func _update()
;$strn=GUICtrlRead(GUICtrlRead($LISTVIEW1))
;$Strnspin=$stringsplit($strn,"|")
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
Select
Case $CmdLine[1] = "T"
Dim $FLD = "TP"
Case $CmdLine[1] = "L"
Dim $FLD = "LED"
Case $CmdLine[1] = "E"
Dim $FLD = "EZKEY"
Case $CmdLine[1] = "B"
Dim $FLD = "BT"
Case $CmdLine[1] = "W"
Dim $FLD = "Wireless"
Case $CmdLine[1] = "M"
Dim $FLD = "MODEM"
Case $CmdLine[1] = "C"
Dim $FLD = "Caram"
Case $CmdLine[1] = "LC"
Dim $FLD = "LCDCRT"
Case $CmdLine[1] = "H"
Dim $FLD = "HDMI"
Case $CmdLine[1] = "O"
Dim $FLD = "ODD"
Case $CmdLine[1] = "U"
Dim $FLD = "USB"
Case $CmdLine[1] = "S"
Dim $FLD = "SPEAKER"
Case $CmdLine[1] = "SELECT"
_select()
Exit
EndSelect
MsgBox(0,"",$FLD &"測試完成!",1)
$TT= _Now()
$update = 'update Sheet1 set '"& $FLD& "' = "'& $CmdLine[1] & '" WHERE T= "' & $TT & '"'
$addfld.Execute($update)
$addfld.close
;$Strn=$FLD
;$Strnspin=StringSplit($Strn,"|")
;$sQuery ="update Sheet1 set TP = '"$CmdLine[1]"' WHERE TP " & " = " & $Strnspin[1]
;$addfld.Execute($sQuery)
;$addfld.Execute("insert into Sheet1 ("&$FLD&",T) values('"&$CmdLine[1]&"','"&$TT&"')")
;$addfld.Execute("insert into Sheet1 ("&$FLD&") values('"&$CmdLine[1]&"')")
EndFunc
Func _select()
;$addfld = ObjCreate("ADODB.Connection")
;$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
;$addfld.Open("select "&$FLD & " from " & $tblname)
;$tmep = $addfld.field(0).value
;MsgBox(0,"",$temp)
EndFunc |
|