• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Problem Populating dropdown using ASP RECORDSET

In the following ASP code, I am trying to retreive data from an AS400 DB to populate a dropdown on a calling a html file.
html file <--> calls ASP file <--> AS 400

Please check the ASP code below first.

I am able to populate the dropdown with the field LVL01 (which is an integer field) but not LVDESC (which is a string field). Interestingly, I am able to *compare* LVDESC in the ASP code as shown in the code. I am not sure where the problem is. Any help is appreciated. When I try to display LVDESC, it shows blank values in the dropdown but shows the exact number of blank options that it should show.

<%
'Keep from defining variables more than one time....
OPTION EXPLICIT

'In order to keep the application from crashing on each error....
ON ERROR RESUME NEXT

'Define the variables....
DIM rsSB
DIM strSQL
DIM option_count
option_count = 0

Session("dbConn") = "DSN=as400; UID=HQODBC; PWD=******"

'Create the Recordset object.  (This is just one of many ways to connect.)
SET rsSB = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT LVDESC, LVL02 FROM HRDBFA.PRPLV PRPLV WHERE  LVL01 = '080' AND LVL03 < '0' AND LVL04 < '0' AND LVL02 > '0' "

rsSB.Open strSQL, Session("dbConn")
%>

<html>
<head>
      <script language="Javascript">
      <!--
      function sendIt(){

            var option_count_js = 0;
            opener.document.myForm._1_1_19_1.options.length = 0;

      <%
      Do While Not rsSB.EOF
      option_count = option_count + 1
      %>
      var optn = opener.document.createElement("OPTION");
                // Funnily the dropdown refuses to accept LVDESC but takes LVL02 and I have no idea why!
      <% if rsSB("LVDESC") <> "undefined" then %>
         optn.text = <%= rsSB("LVDESC") %>        //DOES NOT WORK
                   // optn.text = <%= rsSB("LVL02") %>           //WORKS!
         optn.value = 1;                                          opener.document.myForm._1_1_19_1.add(optn);
                <%  else %>
         optn.text = "2";                                        optn.value = 3;                                       opener.document.myForm._1_1_19_1.add(optn);
      <% end if %>
      <%
      rsSB.MoveNext
      Loop
      %>

      this.close();
      }
      //-->
      </script>
</head>

<body onload="sendIt();">
</body>
</html>

<%
rsSB.Close
SET rsSB = NOTHING

IF Err.number <> 0 THEN
Response.Write "<HR width=""100%"" color=""gray"" size=""1"" align=""left"">"
Response.Write "<DIV style=""background-color: #C0C0C0"">" & Err.number & "<BR>" & Err.Source & "<BR>" & Err.Description & "</DIV>"
Response.Write "<HR width=""100%"" color=""gray"" size=""1"" align=""left"">"
END IF
%>

0
srinivenkat
Asked:
srinivenkat
  • 2
1 Solution
 
GawaiCommented:
wat is the error ?

recheck this line
strSQL = "SELECT LVDESC, LVL02 FROM HRDBFA.PRPLV PRPLV WHERE  LVL01 = '080' AND LVL03 < '0' AND LVL04 < '0' AND LVL02 > '0' "

u have repeated PRPLV ?
0
 
John_LennonCommented:
if rsSB("LVDESC") is a string, i think you need to put quotes around the next line

optn.text = "<%= rsSB("LVDESC") %>"       //DOES NOT WORK

or if you need it to be a number, you can convert it

optn.text = <%= cint(rsSB("LVDESC")) %>       //DOES NOT WORK

check this and see if it works

0
 
srinivenkatAuthor Commented:
Thanks very much. You idea worked exactly the way you suggested. The quotes did the trick. Interestingly cstr(rsSB("LVDESC")) did not work either.

Also, to answer gawai's questions - PRPLV is repeated because that is the syntax for RDB SQL. Like I mentioned earlier, I was getting no error message - only blank fields.

THANKS A LOT!!

Srini
0
 
John_LennonCommented:
glad to help

cstr(rsSB("LVDESC")) will convert rsSB("LVDESC") to a string, you still need to put quotes
cint(rsSB("LVDESC")) will convert rsSB("LVDESC") to a number
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now