?
Solved

populate Combobox from database, but skip blanks

Posted on 2005-05-03
5
Medium Priority
?
262 Views
Last Modified: 2008-03-03
I have a database of usernames with corrosponding real names. I want to populate a combobox so I user can select their name from it. When I build the box it also gives me all the blank names where I don't have real user names listed.  I put in the if statement you see, but it doesn't work. If I put a real name in it will skip it so I know the statement works, it's just the blanks that don't. Is there another way to reference a blank entry in a database other than ""?

<%
var=Session("user")
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=asset"
Set oRS=Server.CreateObject("ADODB.RecordSet")
 
%>
<p>Title: <select size="1" name="title">
<option selected>--Select a User--</option>  
<%
sql = "SELECT Name FROM Users"

oRS.Open sql, Conn,1,2

Do While Not oRS.EOF
      if oRS.Fields("Name").Value = " " then
            oRS.MoveNext
      else
          Response.Write"<Option Value= '" & oRS("Name") &"'>"
          Response.Write oRS("Name") & "</option>"
          oRS.MoveNext
    end if
loop
%>
0
Comment
Question by:t1clausen
  • 3
  • 2
5 Comments
 
LVL 2

Author Comment

by:t1clausen
ID: 13921519
Just realized I threw an extra space in when I posted this it should read:
<%
var=Session("user")
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=asset"
Set oRS=Server.CreateObject("ADODB.RecordSet")
 
%>
<p>Title: <select size="1" name="title">
<option selected>--Select a User--</option>  
<%
sql = "SELECT Name FROM Users"

oRS.Open sql, Conn,1,2

Do While Not oRS.EOF
     if oRS.Fields("Name").Value = "" then
          oRS.MoveNext
     else
         Response.Write"<Option Value= '" & oRS("Name") &"'>"
         Response.Write oRS("Name") & "</option>"
         oRS.MoveNext
    end if
loop
%>
0
 
LVL 20

Accepted Solution

by:
jitganguly earned 1000 total points
ID: 13921538
sql = "SELECT [Name] FROM Users where [name] is not null"
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 13921544
For SQLServer you can use len function

sql = "SELECT [Name] FROM Users where [name] is not null or len([Name]) > 0"
0
 
LVL 2

Author Comment

by:t1clausen
ID: 13921602
That seem to work, but they don't appear in alphabetical order now.... I guess that is a separate question...
0
 
LVL 2

Author Comment

by:t1clausen
ID: 13921673
In case anyone else needs it....

sql = "SELECT Name FROM Users WHERE Name is not null ORDER BY Name asc"
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question