Code Samples -- VBScript
Example #1 - Retrieve Data
<%@ Language=VBScript %> <% Dim oConn, oCommand Dim sResult, sSQL Dim bError Dim i On Error Goto 0 Sub ProcessErr If Err.number <> 0 Then bError = true sResult = "" If oConn.ErrorCode <> 0 Then sResult = "OpenX2 Connection Error: " & oConn.ErrorInfo & ". Error #" & oConn.ErrorCode & " (" & oConn.ErrorCodeEx & ")<br />" Else If oCommand.ErrorCode <> 0 Then sResult = "OpenX2 Command Error: " & oCommand.ErrorInfo & ". Error #" & oCommand.ErrorCode & " (" & oCommand.ErrorCodeEx & ")<br />" End If End If If sResult = "" Then Rem you may reRaise the Error here if you want to allow IIS process rest of errors sResult = "ASP Error: #" & CStr(Err.Number) & ". " & Err.description & "<br />" End If End If End Sub Sub ProcessQuery Set oConn = Server.CreateObject("OpenX2.Connection") Set oCommand = Nothing sResult = "" bError = false sSQL = "SELECT * FROM authors" oConn.Connect("ms_ox1") Set oCommand = oConn.CreateCommand( sSQL, true ) sResult = sResult & "<table border=1><tr>" For i = 1 To oCommand.FieldCount sResult = sResult & "<td><b>" & oCommand.FieldName(i) & "</b></td>" Next sResult = sResult & "</tr>" While oCommand.MoveNext sResult = sResult & "<tr>" For i = 1 To oCommand.FieldCount sResult = sResult & "<td>" & oCommand.FieldValueAsString(i) & "</td>" Next sResult = sResult & "</tr>" Wend sResult = sResult & "</table>" End Sub REM // Main Processing On Error Resume Next ProcessQuery ProcessErr %> <html> <head><title>OpenX2 Test #1 - 'Select * from table'</title></head> <body> <div><%=sResult%></div> </body> </html> |