Code Samples -- VBScript
Example #3 - Simple Query
<%@ Language=VBScript %> <% Set oConn = Server.CreateObject("OpenX2.Connection") Set oCommand = Server.CreateObject("OpenX2.Command") Dim sResult, sParam, sSQL Dim bError sSQL = "SELECT * FROM authors" If Request.Form("param").Count > 0 Then If Not Request.Form("param") = "" Then sParam = Request.Form("param") sSQL = "SELECT :1 as param, authors.* FROM authors WHERE au_lname LIKE :1" End If End If 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 Dim i sResult = "" bError = false oConn.Connect("ms_ox1") oCommand.Connection = oConn oCommand.CommandText = sSQL If Not sParam = "" Then oCommand.ParamValueAsString(1) = sParam End If oCommand.Execute 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 #3 - Parameter in SELECT</title></head> <body> <%= sSQL %> <form action="OX2testVB4.asp" method="post"> <input type="text" name="param"><input type="submit" value="Requery"> <div><%=sResult%></div> </form> </body> </html> |