How return rows and update table with a ODBC connection to a SQL Server from a VBS (Visual Basic Scripting)

Posted by Cereal Monday, July 13, 2009 7:00:00 AM Categories: _Tous les articles VBS / Scripting
Rate this Content 0 Votes

Return rows and update table from a ODBC connection to a SQL Server

1. Create ODBC System to access your DATABASE.
2. Changes values in the code to connect the right ODBC name.

'Return ROW's from a SQL Query
Dim SQLString
'ADODB Object
Set oDB = CreateObject("ADODB.Connection")
'database to open
oDB.Open "WhatsUP-DEV"
'Query that return rows
sSQLQuery = "SELECT sDisplayName, nDeviceID FROM Device"
'Execute query
Set rsResult = oDB.Execute(sSQLQuery)
'Move to first record
rsResult.MoveFirst
'Loop for each rows
Do While Not rsResult.EOF
 'Write values on screen
 WScript.Echo rsResult.Fields("nDeviceID") & " : " & rsResult.Fields("sDisplayName")
 'Move to next record
 rsResult.MoveNext
Loop
'Close connection
oDB.Close


'Update table value from ODBC connection
Dim SQLString
'ADODB Object
Set oDB = CreateObject("ADODB.Connection")
'database to open
oDB.Open "WhatsUP-DEV"
'Query that update a value to 777
sSQLQuery = "UPDATE Device Set nTest = '777' WHERE nDeviceID = '148'"
'Execute query
Set rsResult = oDB.Execute(sSQLQuery)
'Close connection
oDB.Close 
 
Simple-Tech.info
Comments are closed on this post.
Site Map | Printable View | © 2008 - 2012 Simple-Tech.info | Powered by mojoPortal | HTML 5 | CSS | Design by mitchinson