Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2004, 12:37 PM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get information into list box

Can anyone tell me how to put a single list box on a page and have "FName" and "LName" (from my table in database) appear in the listbox? I'm sure it's something simple, but I have no idea how to do it! Please, can someone help me?

 
Old February 4th, 2004, 02:31 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Concatenate your FName and LName fields in a single varibale

Dim Name
Name = rs("FName") & " " & rs("LName")

and use it in your dropdown menu

<option value="<%=Name%>"><%= Name %></option>
 
Old February 5th, 2004, 12:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

You can also combine it in your select statement:

SELECT (FNAME + ' ' + LName) AS FullName FROM [tablename]

Or

SELECT (FNAME & ' ' & LName) AS FullName FROM [tablename]

The top one is for SQL Server and the bottom one is for Access (I believe, I don't work that much in Access). Then you can loop through the recordset using "FullName".
 
Old February 6th, 2004, 10:55 PM
Authorized User
 
Join Date: Jan 2004
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what I have. I don't get any errors now, but the option/list box is empty...What am I doing wrong?

<%
Dim adoCon
Dim rsAdmin
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../database/mercy.mdb")
Set rsAdmin = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT (FNAME & ' ' & LName) AS FullName FROM [tblAdmin]"
rsAdmin.Open strSQL, adoCon
%>
<form name="form1" method="post" action="">
          <select name="select">
            <option value="<%=FullName%>"><%=FullName%></option>
          </select>
        </form>
<%
rsAdmin.Close
Set rsAdmin = Nothing
Set adoCon = Nothing
%>

 
Old February 9th, 2004, 12:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<%
Dim adoCon
Dim rsAdmin
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../database/mercy.mdb")
Set rsAdmin = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT (FNAME +' '+LName) AS FullName FROM tblAdmin"

rsAdmin.Open strSQL, adoCon
%>
<form name="form1" method="post" action="">
          <select name="select">
            <option value="<%=FullName%>"><%=FullName%></option>
          </select>
        </form>
<%
rsAdmin.Close
Set rsAdmin = Nothing
Set adoCon = Nothing
%>



Quote:
quote:Originally posted by stacy
 This is what I have. I don't get any errors now, but the option/list box is empty...What am I doing wrong?

<%
Dim adoCon
Dim rsAdmin
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../database/mercy.mdb")
Set rsAdmin = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT (FNAME & ' ' & LName) AS FullName FROM [tblAdmin]"
rsAdmin.Open strSQL, adoCon
%>
<form name="form1" method="post" action="">
         <select name="select">
            <option value="<%=FullName%>"><%=FullName%></option>
         </select>
        </form>
<%
rsAdmin.Close
Set rsAdmin = Nothing
Set adoCon = Nothing
%>

 
Old February 12th, 2004, 10:54 AM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'LL TRY TO GIVE SOME HELP.
Sorry for the inexperienced (it's my first post)

What I see is missing is the loop thru the records in te recordset.

You have to llop thru each record in order to achieve the FName, LName pair to put it in the option of the select.

So here's th e code for before and after your line <option value="<%=FullName%>"><%=FullName%></option>

Before
<% Do While Not rsAdmin.Eof %>

I'll also change a little the select option clause just in case
<option value="<%=rsAdmin("FullName)%>"><%=rsAdmin("FullNa me")%></option>

And After
<% rsAdmin.Movenext
   Loop %>

That's all (I havn't test it, may be you find something to check)

Best regards
Tell me if it works

Quote:
quote:Originally posted by mateenmohd
 <%
Dim adoCon
Dim rsAdmin
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../database/mercy.mdb")
Set rsAdmin = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT (FNAME +' '+LName) AS FullName FROM tblAdmin"

rsAdmin.Open strSQL, adoCon
%>
<form name="form1" method="post" action="">
         <select name="select">
            <option value="<%=FullName%>"><%=FullName%></option>
         </select>
        </form>
<%
rsAdmin.Close
Set rsAdmin = Nothing
Set adoCon = Nothing
%>



Quote:
quote:Originally posted by stacy
 This is what I have. I don't get any errors now, but the option/list box is empty...What am I doing wrong?

<%
Dim adoCon
Dim rsAdmin
Dim strSQL
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../database/mercy.mdb")
Set rsAdmin = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT (FNAME & ' ' & LName) AS FullName FROM [tblAdmin]"
rsAdmin.Open strSQL, adoCon
%>
<form name="form1" method="post" action="">
         <select name="select">
            <option value="<%=FullName%>"><%=FullName%></option>
         </select>
        </form>
<%
rsAdmin.Close
Set rsAdmin = Nothing
Set adoCon = Nothing
%>

 
Old February 20th, 2004, 01:08 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

Make sure you have that loop inside of your select tags as well or you will get multiple list boxes.

<select name="select">
<%Do While Not rsAdmin.Eof%>
<option value="<%=rsAdmin("FullName)%>"><%=rsAdmin("FullNa me")%></option>
<%
rsAdmin.movenext
loop
%>
</select>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.