 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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
|
|
|

April 21st, 2004, 01:12 PM
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
|

April 21st, 2004, 08:23 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
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.
======================================
|

April 22nd, 2004, 02:55 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

April 22nd, 2004, 03:07 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
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.
======================================
|

April 22nd, 2004, 08:45 AM
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 22nd, 2004, 09:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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)
|

April 22nd, 2004, 09:23 AM
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 22nd, 2004, 02:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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)
|

April 23rd, 2004, 07:57 AM
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 23rd, 2004, 08:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|
 |