If IsString(_SelectData("Select MachineType From " & $tblname & " where PCName='" & $PCName & "'")) Then ;没有要查询的数据
;msgBox(0, $PCName, "没有查询到这台电脑的记录")
;MsgBox(0, "以下数据将写入数据库", $MachineType & " " & $MachineName & " " & $PCName & " " & $IPAddress & " " & $MachineStatus & " " & $SoftwareRev & " " & $ClientRev & " " & $MacAddress & " " & $UpdateDateTime)
_AddDataToDB($MachineType, $MachineName, $PCName, $IPAddress, $MachineStatus, $SoftwareRev, $ClientRev, $MacAddress, $UpdateDateTime)
Else
;MsgBox(0, $PCName, "查询到有这台电脑的记录")
_UpdateData($MachineType, $MachineName, $PCName, $IPAddress, $MachineStatus, $SoftwareRev, $ClientRev, $MacAddress, $UpdateDateTime)
EndIf
;更新指定的数据
Func _UpdateData($MachineType, $MachineName, $PCName, $IPAddress, $MachineStatus, $SoftwareRev, $ClientRev, $MacAddress, $UpdateDateTime)
$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("update " & $tblname & " set MachineType = '" & $MachineType & "', PCName = '" & $PCName & "', IPAddress = '" & $IPAddress & "', MachineStatus = '" & $MachineStatus & "', SoftwareRev = '" & $SoftwareRev & "', ClientRev = '" & $ClientRev & "', MacAddress = '" & $MacAddress & "', UpdateDateTime = '" & $UpdateDateTime & "' where MachineName = '" & $MachineName & "'")
$addfld.close ;写完结束所有的连接
EndFunc ;==>_UpdateData
;选择是否有指定字段的数据
Func _SelectData($sqlstr) ;查询数据库 ,返回数组,宏保存记录个数
Local $ret = ""
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open($sqlstr)
If $RS.bof And $RS.eof Then
SetError(1)
Else
SetError(0)
$ret = $RS.GetRows
EndIf
$RS.close()
$addfld.Close
Return $ret
EndFunc ;==>_SelectData
|