‎03-17-2009 05:31 PM
‎03-17-2009 06:03 PM
#include <_CSVLib_V1.3.au3>
#include <Array.au3>
$path = @ScriptDir & "\datafile.csv"
Func _SQLCon($scIP, $scUser, $scPass, $scDB)
$Objconn = ObjCreate("ADODB.Connection")
$Objconn.Open ("Provider=SQLOLEDB; Data Source=" & $scIP & "; User ID=" & $scUser & "; Password=" & $scPass & "; database=" & $scDB & ";")
Return $Objconn
EndFunc ;==>_SQLCon
Func _SQLQuery($oConnectionObj, $iQuery)
If IsObj($oConnectionObj) Then
Return $oConnectionObj.Execute($iQuery)
EndIf
EndFunc ;==>_SQLQuery
Func _SQLEnd($Objconn)
If IsObj($Objconn) Then
$Objconn.close
EndIf
EndFunc ;==>_SQLEnd
$sql = _SQLCon("Server\instance", "lssqluser", "password", "Database")
$records=_CSVFileReadRecords($path)
$numrecords = _CSVRecordsGetFieldValue($records, 0, 0)
For $f = 1 To $numrecords
$computername=_CSVRecordsGetFieldValue($records, 1, $f)
$username=_CSVRecordsGetFieldValue($records, 2, $f)
$sqlstring= "UPDATE tblCustInventory SET UserName = '"& $username & "' WHERE (ComputerName = '" & $computername & "')"
$query = _SQLQuery($sql, $sqlstring)
Next
_SQLEnd($sql)
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now