Classic ASP - Retrieve column from SQL Server Database

Hi Experts,
I'm updating a field in my table with a dropdown, which is populated from a different table:
This is the dropdown:

<select name="DestQueueId">
<%
Dim rsName
set rsName=Server.CreateObject("ADODB.recordset")
sql="SELECT distinct(Name), QueueEnvironmentId FROM QueueEnvironment order by Name"
Set rsName = AdoCon.Execute(sql)
%>
<option value="">Change Environment:</option>
<%
Do While Not rsName.EOF
Response.Write "<option value='" & rsName("QueueEnvironmentId") & "'>"& rsName("Name") &"</option>"
rsName.MoveNext
Loop
Response.Write "</select>"
%>
<input type="Submit" name="Submit" value="Submit" />

Open in new window


After I submit, the DestQueueId column is updated in my table with the value of QueueEnvironmentId.
QueueEnvironmentId is an integer.
Name is a string.
When I view  <%=rs("DestQueueId")%> on my updated page, the integer is displayed.
How could I have the Name string displayed instead?

I would appreciate your help.
romsomIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
here's a function you can call to get the NAME for a given ID:
<%
Response.Write getNameFromID( rs("DestQueueId") )

function getNameFromID( id )
   Dim rsName, results
   set rsName=Server.CreateObject("ADODB.recordset")
   sql="SELECT [Name] FROM QueueEnvironment where DestQueueId = " & id
   Set rsName = AdoCon.Execute(sql)

   if not rsName .BOF and not rsName .EOF then 
       results = rsName("Name")
    end if

    getNameFromID = results
end function
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romsomIT DeveloperAuthor Commented:
Where do I have to place this code? Shall I replace <%=rs("DestQueueId")%> ?
Now it gives me an error message:
Microsoft VBScript compilation error '800a03ea'

Syntax error

/RecallAffiliation.asp, line 208

function getNameFromID( id )
^
0
Big MontyWeb Ninja at largeCommented:
the function can go anywhere in your code.

replace

<%=rs("DestQueueId")%>

with

<%=getNameFromID( rs("DestQueueId") )%>
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

romsomIT DeveloperAuthor Commented:
I replaced <%=rs("DestQueueId")%> with <%=getNameFromID( rs("DestQueueId") )%>
but no matter where put the function on my page it still gives me the syntax error message at the this line:
function getNameFromID( id )
0
romsomIT DeveloperAuthor Commented:
This is what my page looks like now:
<%
Response.Write getNameFromID( rs("DestQueueId") )

function getNameFromID( id )
   Dim rsName, results
   set rsName=Server.CreateObject("ADODB.recordset")
   sql="SELECT [Name] FROM QueueEnvironment where QueueEnvironmentId = " & id
   Set rsName = AdoCon.Execute(sql)

   if not rsName .BOF and not rsName .EOF then 
       results = rsName("Name")
    end if

    getNameFromID = results
end function
%>

<table>
<tr>
<td>Alias Name</td>
<td>Host Name</b></td>
<td">Env</td>
</tr>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
%>
<tr>
<td><%=rs("AliasName")%></td>
<td><%=rs("HostName")%></td>
<td><%=getNameFromID( rs("DestQueueId") )%></td>
</tr>
<%
	rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing

%>
</table>

Open in new window


The error I get now is as follows:
Microsoft VBScript compilation error '800a03f9'

Expected 'Then'

/test.asp, line 56

if not rsName .BOF and not rsName .EOF then
--------------^
0
Big MontyWeb Ninja at largeCommented:
change that line to

if not rsName.BOF and not rsName.EOF then
0
romsomIT DeveloperAuthor Commented:
Great, now it's perfect, thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.