We have some old code on our site that is exposed to some longtime clients upon login. For years, parts of it haven't returned the right data, and we've just rolled with it. The other day, I got the assignment from the boss to figure out why it reads that way. As someone who has worked on LAMP stack and now Node and just barely dabbled in .NET for the web despite having some C# and VBA stuff I occasionally do in-house, I don't quite know where to start, except that it's obvious that two of the fields in the query aren't being mapped from the recordset object to the ASP engine for display. That is, when I run the query from the stored procedure, it returns the desired columns with the desired names, but when it comes to displaying on the web site, they simply show up blank or apparently return "Empty" strings.
So, the code has this on the page:
<% Set objConnection = Server.CreateObject("ADODB.Connection") objConnection.Open "DSN=OurDSN" SQLQuery = "exec sp_thepayments " & Request.querystring("claimid") Set rsCustomersList = objConnection.Execute(SQLQuery) %>
I have also tried using the rs.Open instead of Execute:
<%
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open "DSN=OurDSN"
SQLQuery = "exec sp_thepayments " & Request.querystring("claimid")
'Set rsCustomersList = objConnection.Execute(SQLQuery)
Set rsCustomersList = Server.CreateObject("ADODB.recordset")
rsCustomersList.Open SQLQuery, objConnection
%>
It works the same way.
Then, later the table is created:
<tbody><% Do Until rsCustomersList.EOF%><tr><td class="amount"><% if ISNULL(rsCustomersList("clmpmt_amt")) then %><p>$0.00 <% else %> <%= formatcurrency (rsCustomersList("clmpmt_amt"))%> <% end if %> </td><td><% if ISNULL(rsCustomersList("clmpmt_date")) then %><p><% else %> <%= formatdatetime (rsCustomersList("clmpmt_date"),2)%> <% end if %> </td><td><%= rsCustomersList("chk_nbr")%></td><td><% if ISNULL(rsCustomersList("chk_date")) then %><p><% else %> <%= formatdatetime (rsCustomersList("chk_date"),2)%> <% end if %></td><td><% strtype = rsCustomersList("clmpmt_type")%><%If rsCustomersList("clmpmt_type") = "c" Then %> Customer<% Else %><%Response.Write(strtype)%>Vendor<% End If %><%If IsEmpty(rsCustomersList("clmpmt_type")) Then%>• rsCustomersList("clmpmt_type") is Empty<% Else %>"<%= strtype%>"<% End If %></td><td><%= rsCustomersList("wt_item")%></td><td><%= rsCustomersList("claimobj_desc")%></td><td><%= rsCustomersList("loss_name")%></td></tr><% rsCustomersList.MoveNext Loop %></tbody>
So, what I'm finding through reading is that it's basically setting up a recordset object which is calledrsCustomersList in this case. It processes each member of the recordset using theDo Until...Loop. On each loop, it creates a row in the table. The<%= %> seems to be a shortcut or alternative for the Response.Write() method. Each item in thersCustomersList("...") style is a value in a column in the recordset represented by the column name in quotes for that particular row as it loops. Apparently, you can address the value of a column for that recordset row by specifyingrsCustomersList("clmpmt_date") for example. However, what I'm finding is that it isn't able to display the values of Customer or Vendor based on theIf rsCustomersList("clmpmt_type") = "c"Then... As you can see, it appears thatstrtype [and rsCustomersList("clmpmt_type") for that matter] are always empty. I added some test code in there, to verify that it is indeedempty. The code is working, I am just not getting the output I expect.
So, my first thought was that the query is not returning a value for that column, but tests on the SQL server for that stored procedure reveal that it is indeed working as intended. The SQL query is correct as written. The spelling of the column matches, too.
Finally, I thought that maybe the stored procedure it is calling is not the one I'm looking at (maybe a different server instance or database), but no when I edit the stored procedure, the website displays different data, so I am working on the correct SQL
query on the server. I thought maybe that it has something to do with the logic in the VBScript that is supposed to convert the "c" toCustomer and everything else to Vendor, but no I'm having the same problem with the<%= rsCustomersList("loss_name")%> not displaying even when the SQL query in the stored procedure is returning values for "loss_name".
Anyone have any ideas or can point me how to debug this?