Code Samples -- VBScript
Example #2 - Sorting
<%@ Language=VBScript %> <% Set oConn = Server.CreateObject("OpenX2.Connection") Set oCommand = Server.CreateObject("OpenX2.Command") Dim sResult, sSQL, sOrderBy Dim bError sOrderBy = "au_lname" if Request.Form("newOrder").Count > 0 Then sOrderBy = Request.Form("newOrder") End If sSQL = "SELECT au_fname + ' ' + au_lname, phone, address, city, state, zip FROM authors ORDER BY " & sOrderBy 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 oCommand.Execute While oCommand.MoveNext() sResult = sResult & "<tr>" For i = 1 To oCommand.FieldCount sResult = sResult & "<td>" & oCommand.FieldValueAsString(i) & "</td>" Next sResult = sResult & "</tr>" Wend End Sub REM // Main Processing On Error Resume Next ProcessQuery ProcessErr %> <html> <head><title>OpenX2 Test #2 - ORDER BY</title> <script type="text/javascript" language="JavaScript"> <!-- var sCurOrder = "<%= sOrderBy %>"; function ChangeOrder(sNewOrder) { if(sCurOrder != sNewOrder) { reorder.newOrder.value = sNewOrder; reorder.submit(); } } --> </script> </head> <body> <% If bError Then %> <div><%=sResult%></div> <% Else %> Click on column caption to sort by it <form action="OX2test2.asp" method="post" name="reorder" id="reorder"> <input type="hidden" name="newOrder" id="newOrder" value="au_lname"> <table border="1"> <tr> <td style="cursor: hand;" onClick="ChangeOrder('au_lname')"><b>Name</b></td> <td style="cursor: hand;" onClick="ChangeOrder('phone')"><b>Phone</b></td> <td style="cursor: hand;" onClick="ChangeOrder('address')"><b>Address</b></td> <td style="cursor: hand;" onClick="ChangeOrder('city')"><b>City</b></td> <td style="cursor: hand;" onClick="ChangeOrder('state')"><b>State</b></td> <td style="cursor: hand;" onClick="ChangeOrder('zip')"><b>Zip</b></td> </tr> <%=sResult%> </table> <form> <% End If %> </body> </html> |