#197243 - 2009-12-30 10:26 PM
Modify VBS to KiXtart Scrpit
|
AModestProposal
Fresh Scripter
Registered: 2009-12-30
Posts: 5
Loc: Tonadawanda, NY
|
Hello, I'm rather new to this so go easy on me. I am in the process of converting scripts at work written in VBS and converting them to KitXtart scripts. I have run into a problem trying to convert the following lines of code.
Dim SQL
SQL = "INSERT INTO Login (UserName, ComputerName, LoginDateTime)VALUES('" & UserName & "', '" & ComputerName & "', '" & Now() & "' )"
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; data source=\\server\login.mdb; User ID=user; password=password; Persist Security Info=True; Jet OLEDB:System database=\\server\security.MDW;"
objRS.ActiveConnection = objConnection
objRS.CursorLocation = 2
objRS.Open SQL, objConnection, 3, 3
objConnection.Close
I converted the following
$SQL = "INSERT INTO Login (UserName, ComputerName, LoginDateTime)VALUES('" & $UserName & "', '" & $ComputerName & "', '" & $CurrentDate & "' )"
$objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; data source=\\server\login.mdb; User ID=user; password=password; Persist Security Info=True; Jet OLEDB:System database=\\server\security.MDW;')
$objRS.ActiveConnection = $objConnection
$objRS.CursorLocation = 2
I can't get this code to convert "objRS.Open SQL, objConnection, 3, 3"
Any help would be appreciated.
Edited by Allen (2009-12-30 11:35 PM) Edit Reason: added code tags
|
Top
|
|
|
|
#197245 - 2009-12-30 11:14 PM
Re: Modify VBS to KiXtart Scrpit
[Re: Allen]
|
AModestProposal
Fresh Scripter
Registered: 2009-12-30
Posts: 5
Loc: Tonadawanda, NY
|
I believe all of that is part of the SQL statement.
|
Top
|
|
|
|
#197254 - 2009-12-31 03:39 PM
Re: Modify VBS to KiXtart Scrpit
[Re: Glenn Barnas]
|
AModestProposal
Fresh Scripter
Registered: 2009-12-30
Posts: 5
Loc: Tonadawanda, NY
|
I have tried the suggestion here but has not changed the outcome. How do I convert this statement in VBS to KiXtart,
"objRS.Open SQL, objConnection, 3, 3"
That is the only section that errors out. I should have pointed out that my variable objRS is my ADODB.recordset and objConnection is my ADODB.Connection.
Thanks for the help so far.
Edited by AModestProposal (2009-12-31 03:39 PM)
|
Top
|
|
|
|
#197255 - 2009-12-31 03:51 PM
Re: Modify VBS to KiXtart Scrpit
[Re: AModestProposal]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Hmm...
Did you try just:
$objRS.Open($SQL, $objConnection, 3, 3)
|
Top
|
|
|
|
#197256 - 2009-12-31 04:00 PM
Re: Modify VBS to KiXtart Scrpit
[Re: Richard H.]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Alternatively:
$objRS.ActiveConnection = $objConnection
$objRS.CursorLocation = 2
$objRS.LockType=3
$objRS.CursorType=3
$objRS.Open($SQL)
|
Top
|
|
|
|
#197258 - 2009-12-31 04:20 PM
Re: Modify VBS to KiXtart Scrpit
[Re: Richard H.]
|
AModestProposal
Fresh Scripter
Registered: 2009-12-30
Posts: 5
Loc: Tonadawanda, NY
|
First thing I tried, my error catching is a returning an error. Also looking at said Database I can see my entries are not appearing.
|
Top
|
|
|
|
#197259 - 2009-12-31 05:08 PM
Re: Modify VBS to KiXtart Scrpit
[Re: AModestProposal]
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$cnstring = "DRIVER={SQL Server};SERVER=sql2;UID=Inventory;PWD=script;DATABASE=invdb"
$cn = CreateObject("ADODB.Connection")
$cmd= CreateObject("ADODB.Command")
$rs = CreateObject("ADODB.RecordSet")
$cn.connectionstring = $cnstring
$cn.open
$cmd.activeconnection = $cn
$rs.cursortype = 3
$rs.locktype = 3
$rs.activecommand = $cmd
$cmdtxt = "select * from dbo._tbl_Main where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd) ;? 'Error = '+@ERROR+' - '+@SERROR
IF $rs.eof = -1 $rs.addnew ENDIF
$rs.fields.item("SerialNumber").value = $serNo
$rs.fields.item("ComputerName").value = @wksta
$rs.fields.item("AssignedTo").value = $assigned
$rs.fields.item("NetworkID").value = $network
$rs.fields.item("IPAddress").value = $ip
$rs.fields.item("InvDate").value = @date
$rs.fields.item("Version").value = $InvVer
$rs.update ;? 'Error = '+@ERROR+' - '+@SERROR
$rs.close
|
Top
|
|
|
|
#197260 - 2009-12-31 05:47 PM
Re: Modify VBS to KiXtart Scrpit
[Re: Radimus]
|
AModestProposal
Fresh Scripter
Registered: 2009-12-30
Posts: 5
Loc: Tonadawanda, NY
|
$cnstring = "Provider=Microsoft.Jet.OLEDB.4.0; data source=\\server\login.mdb; User ID=blank; password=blank; Persist Security Info=True; Jet OLEDB:System database=\\server\Mueller.MDW;'"
$cn = CreateObject("ADODB.Connection")
$cmd= CreateObject("ADODB.Command")
$rs = CreateObject("ADODB.RecordSet")
Dim $Sql
$Sql = "INSERT INTO Login (UserName, ComputerName, LoginDateTime)VALUES('"
$Sql = $Sql + $UserName + "', '"
$Sql = $Sql + $ComputerName & "', '"
$Sql = $Sql + $CurrentDate + "' )"
;'Sql Statement is' ? $Sql ?
$cn.connectionstring = $cnstring
$cn.open
$cmd.activeconnection = $cn
$rs.cursortype = 3
$rs.locktype = 3
$rs.activecommand = $cmd
$cmdtxt = "$SQL"
$cmd.commandtext = $cmdtxt $rs.open ($cmd) ? 'Error = '+@ERROR+' - '+@SERROR
IF $rs.eof = -1 $rs.addnew ENDIF
; $rs.fields.item("SerialNumber").value = $serNo
; $rs.fields.item("ComputerName").value = @wksta
; $rs.fields.item("AssignedTo").value = $assigned
; $rs.fields.item("NetworkID").value = $network
; $rs.fields.item("IPAddress").value = $ip
; $rs.fields.item("InvDate").value = @date
; $rs.fields.item("Version").value = $InvVer
$rs.fields.item("UserName").value = @USERID
$rs.fields.item("ComputerName").value = @WKSTA
$rs.fields.item("LoginDateTime").value = @DATE
$rs.update ? 'Error = '+@ERROR+' - '+@SERROR
$rs.close Now i am getting an error message saying delete, insert, update, select not allow with a closed object. Sorry, i just don't seem to be getting this.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|