p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   Fill a drop down box with table names? (http://p2p.wrox.com/showthread.php?t=12109)

morpheus April 21st, 2004 01:12 PM

Fill a drop down box with table names?
 
I have an sql database, I want to fill a drop down box with the names of all the tables in my database.

<%
SQLStr="SELECT * FROM INFORMATION_SCHEMA.TABLES"
Set RS=Server.CreateObject("ADODB.Recordset")
RS.Open SQLStr,Application("DBConn"),adOpenKeyset,adLockPe ssimistic,adCmdText
%>

I use this to show all the tables, then I thought I could use this to fill the box

<select name="Table">
<option value="<%RS=("TABLE_NAME")%>"</option>
</select>

It just gives me an empty box :-(, I am not sure if I am even going about this the right way, tell me what you think.

Thanks


rodmcleay April 21st, 2004 08:23 PM

I am not sure about the query itself as I have never tried to list the tables but I can see that there is some errors in the creation of the dropdown box.

Try
Code:

<select name="Table">
while not RS.EOF
<option value="<%= RS("TABLE_NAME")%>"</option>
RS.MoveNext
WEND
</select>

The difference being that the options are added in a loop, as well as there was a syntax error in you server side script tag.

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================

pgtips April 22nd, 2004 02:55 AM

There's still a syntax error - the opening option tag hasn't been closed. But the bigger problem is that you aren't writing out anything for the user to see! The basic syntax for an option tag is:
<option value="this is what gets posted>this is what the user sees

so you probably want to repeat the tablename like this:
<option value="<%= RS("TABLE_NAME")%>"><%= RS("TABLE_NAME")%></option>

rgds
Phil

rodmcleay April 22nd, 2004 03:07 AM

Cheers Phil, for picking that up.
Did not really look past the RS=("TABLE_NAME") error.
Goes to show if someone has an error, don't cut and paste THEIR code.


======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================

morpheus April 22nd, 2004 08:45 AM

Okay thanks guys it seems to work, but I am only getting the first table name, and no more. Everything seems right.

<select name="Table">
while not RS.EOF
<option value="<%=RS("TABLE_NAME")%>"><%=RS("TABLE_NAME")% ></option>
RS.MoveNext
wend
</select>

Let me know if there is something wrong here.

Thanks


Imar April 22nd, 2004 09:05 AM

It's because you don't have your While Wend stuff in a server side ASP block. Change it to this:
Code:

<select name="Table">
<% while not RS.EOF %>
<option value="<%=RS("TABLE_NAME")%>"><%=RS("TABLE_NAME")%></option>
<%
  RS.MoveNext
  wend
%>

</select>

Alternative, create one ASP code block that uses Response.Write statements to write out all the <option> elements. This will perform a little faster.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: No Hope by Motorpsycho (Track 4 from the album: Wrenched)


morpheus April 22nd, 2004 09:23 AM

Thanks Imar, that helps a lot. Okay I got a question for you. If you had an sql database and no access to sql server tools. what would you use to add/delete tables?
 Is there a better way than using asp?

Thanks


Imar April 22nd, 2004 02:11 PM

It depends a bit on your setup and situation. It it's a one time operation, you could ask the admin of your system to restore a database backup or to attach a copy of a (design-time) database.

If you have a public SQL Server, you can use DTS to synchronize your development database and the live server.

But if all you can do is change the database with SQL statements remotely, ASP is as good a solution as anything else.

Personally, I would try to keep "live changes" to a minimum. Sooner or later your database schemas will get out of sync and you'll run into problems. Is there no way to manage your server "properly"? That is, with tools like the Enterprise Manager?
Although it's a .NET solution, you could take a look at the Web Data Administrator. According to Microsoft, this tool " enables you to easily manage your SQL Server data wherever you are". I used it a couple of times, and it looks pretty good (it looks similar to the EM of SQL Server, but it's Web based).

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Undertow by Tool (Track 7 from the album: Undertow)


morpheus April 23rd, 2004 07:57 AM

I have looked at the Web Data Administrator, but I am not sure how to use it, I email the people that host our database and website and they said I could use "web service" to connect the the database, but they wouldn't elaborate on that and I am not sure what it means. Dosen't a copy of SQL server tools come in the book beginninh SQL server 2000? I thought it came with a cd but I can't seem to find it. To answer your question, no I don't have a proper way to connect to the database. It was fine at first, but now I need to delete and add new tables and I don't want to use asp for that. :-(
Anyways if you could give me some tips on Web Data Administrator or know where I can get a copy of EM that would be great.

Thanks


Imar April 23rd, 2004 08:02 AM

Hmmm, maybe your ISP has a tool much like the Web Admin somewhere?

If they are not willing to provide more information, personally I wouldn't consider them a valuable host. How can they serve you well if they don't allow you to manage your databases and are not even willing to provide more information? Isn't there a help or FAQ section on their site with more info?

Anyway, AFAIK, there is a Trial version (120 days) of SQL Server that you can download from the Microsoft site. It comes with the EM.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.



All times are GMT -4. The time now is 01:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.