Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > BOOK: Beginning ASP 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 12th, 2008, 02:02 PM
Authorized User
 
Join Date: Oct 2008
Location: , , Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening distinct files in a database Link Column

Hi Guys,

  I have a field in my database(which i have programmed to display in an ASP page)
  and that field/Column has texts
  in it. These texts are links (when you click any of them they
  open up a certain document).

  The Problem:

  I am trying to see how i can program these text values in this
  particular field/Column (the field/Column name is called "Links")
  to open up different files when clicked on.Not the same file
  as my code will show you.

  Other Information you may need to know:

  The idea behind this (above) is that each text is not
  to be input in code. I have an html form I programmed.
  These form has two text boxes called "Link" and "File Path".

  About the Link Textbox
          The link textbox is where i put in the name of what i want the link to a document to be called (and displayed in my database).
  About the File Path Textbox
         The file Path Textbox is where i put in the path to any document i want.

  How it all works.

       The idea is when i have filled both textboxes with the appropriate information
        i will post them to my display form (my asp page that displays the database when "UPDATED").
       What should happen is when i click on any of these texts in the field named "Link"
         it should open up the file associated with the File path i Input in the "File path"
          text box.

       Here is my code Below:

<%option explicit%>

<html>
<head><title>ADO - List Database Records</title></head>
<body>
<%



Dim oConn, oRs, strConn,SQL
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= C:/Inetpub/wwwroot/MyWebProjects/Manual.mdb"
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open strConn


Set oRs=Server.CreateObject("ADODB.Recordset")
oRs.Open "SELECT Link FROM Orders",oConn
oRs.MoveFirst
%>
<TABLE BORDER=1 COLS=<% = oRs.Fields.Count %>>
   <TR>
    <%Dim oField
    For Each oField In oRs.Fields %>
      <TH> <% = oField.Name %></TH>
      <% Next %>
      </TR>

<%Do While Not oRs.EOF %>
   <TR>
   <%For Each oField In oRs.Fields%>
       <TD ALIGN=RIGHT>

    'This is where you probably want to look first because all the links open only that document(REZ_APPLICATION.pdf)
    'i dont even want the document name to be here (in code)

       <A HREF="REZ_APPLICATION.pdf"><%= oRs.Fields("Link")%></A>
       <%If IsNull(oField) Then
           Response.Write "NULL"
          Else
           Response.Write "&nbsp;"
         End If
       %>

       </TD>
       <% Next
       oRS.MoveNext%>
       </TR>
    <% Loop %>
</TABLE>
<%
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing
%>

<h3>
  <A HREF="Records1_2.htm">Click here to add a Form</A>
</h3>
</body>
</html>

      Thats it.


      All suggestions are welcome.


      Thank you all in advance.







  #2 (permalink)  
Old November 12th, 2008, 02:12 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. Why not just build an anchor tag during the post of your form and pass that into the database?

So if the first textbox had the value "Super cool PDF" and the second textbox had the value "/media/pdf/supercool.pdf" you could build an anchor such as:

Dim s
s = "<a href='" & Request.Form("textBox2") & "'>" & Request.Form("textBox1") & "</a>"

which would pass this into your database: <a href='/media/pdf/supercool.pdf'>Super cool PDF</a>

When your page pulled the value from the database it would display the link as such.

Does that help?


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #3 (permalink)  
Old November 12th, 2008, 04:18 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

This is the SAME QUESTION you asked before in this SAME FORUM. And then you ALSO cross-posted in the ASPMessageBoard.com forums.

In any case, you SAID that my answer in the other thread in this forum worked. Now you are asking the same question again. WHY???
  #4 (permalink)  
Old November 12th, 2008, 06:21 PM
Authorized User
 
Join Date: Oct 2008
Location: , , Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 This is the SAME QUESTION you asked before in this SAME FORUM. And then you ALSO cross-posted in the ASPMessageBoard.com forums.

In any case, you SAID that my answer in the other thread in this forum worked. Now you are asking the same question again. WHY???

 yes your code worked.
 and thank you for it.
 But it did not answer the question i was trying to deal with. It only turned a particular field in my DB into links. Now these links open only one file which should not be the case.
   I am sorry if i have offended you or broken any of the posting rules but i was certainly happy when i figured out your code and used it to turn one field into links.
     Once again thank you.


  #5 (permalink)  
Old November 12th, 2008, 07:48 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Gene, did my response answer your question?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #6 (permalink)  
Old November 12th, 2008, 08:39 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
quote:
... It only turned a particular field in my DB into links. Now these links open only one file which should not be the case....
Well, sure it did, the way you coded it.

You did:
      <A HREF="REZ_APPLICATION.pdf"><%= oRs.Fields("Link")%></A>
So *EVERY* link will go to "REZ_APPLICATION.pdf"

*MY* suggestion was to use
     <A HREF="<%=oRs("Link")%>" > <%=oRs("Name")%> </A>

You SAID that you have your users enter BOTH a name AND a link. So if you store BOTH the name and link in the DB--and if you then *retrieve* both link and name--you have two separate values and you can use them separately for the purpose intended! One is the link, so it goes in the HREF, where a link would logically go. The other is the name, so *that* is what you display to the user. (The link is hidden in the HTML.)

Now, the other major mistake you have is your SQL query.

You are doing
    oRs.Open "SELECT Link FROM Orders",oConn
so that *ONLY* gets you the LINK from the table.

You *need* to get BOTH the name and link:
    oRs.Open "SELECT Link, Name FROM Orders",oConn
  #7 (permalink)  
Old November 12th, 2008, 08:46 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

DPARSONS: You need to read his other thread.

He has a <FORM> with two text fields, NAME and LINK.

He gets input from those fields and *apparently* is succesfully storing those values in the DB (else he would be getting nothing at all back in the recordset).

Then he just wanted to use the links to get to the files named (or described, maybe, instead of named...same difference).

Here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=75053

Quote:
quote:The names for these links are supplied by the user not in code but by typing it into a textbox and by typing the path to the document in another textbox regardless of the name of the document.
  #8 (permalink)  
Old November 12th, 2008, 10:18 PM
Authorized User
 
Join Date: Oct 2008
Location: , , Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:Originally posted by dparsons
Quote:
 Gene, did my response answer your question?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========

Dparsons,
     I tried your code and it worked. The code is certainly correct. But i think it is in the wrong form (that is the wrong ASP form which is the "display form"). So instead of turning the desired field into Links that contain the texts from that Field's Column this is what i am getting.

<A HREF="<%=oRs("Link")%>" ><%=oRs("Name")%></A>

 <%=oRs("Name")%>

I am trying to figure out which form it should be in among the 3 forms i have got
(The display form that contains all my database display,
The Posting form with textboxes
or
The Form that processes the input from the textboxes and posts the updated record to my display form)

I was also wondering if the textbox that holds input for the document Path ( it's purely HTML in this form) should have an <input type=File>
for this to work effectively. The type=Text for now.

Once Again,
Thank you




  #9 (permalink)  
Old November 12th, 2008, 10:30 PM
Authorized User
 
Join Date: Oct 2008
Location: , , Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 
Quote:
quote:
Quote:
... It only turned a particular field in my DB into links. Now these links open only one file which should not be the case....
Well, sure it did, the way you coded it.

You did:
     <A HREF="REZ_APPLICATION.pdf"><%= oRs.Fields("Link")%></A>
So *EVERY* link will go to "REZ_APPLICATION.pdf"

*MY* suggestion was to use
     <A HREF="<%=oRs("Link")%>" > <%=oRs("Name")%> </A>

You SAID that you have your users enter BOTH a name AND a link. So if you store BOTH the name and link in the DB--and if you then *retrieve* both link and name--you have two separate values and you can use them separately for the purpose intended! One is the link, so it goes in the HREF, where a link would logically go. The other is the name, so *that* is what you display to the user. (The link is hidden in the HTML.)

Now, the other major mistake you have is your SQL query.

You are doing
    oRs.Open "SELECT Link FROM Orders",oConn
so that *ONLY* gets you the LINK from the table.

You *need* to get BOTH the name and link:
    oRs.Open "SELECT Link, Name FROM Orders",oConn
Old Pedant,
    Thank You. I am going to give it a try now and see how it goes. I realized i did not have a field in my database to store the Links ( Links to mean the "path" to the document, this i am not too sure how it would go in an access DB cause i might have to specify the data type which i am guessing to be OLE/ODBC (that is if it is possible for me to only store document URL's in one field in an ACCESS DB))

Thank You for all your help so far. I have learnt a lot.

  #10 (permalink)  
Old November 13th, 2008, 03:16 PM
Authorized User
 
Join Date: Oct 2008
Location: , , Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 
Quote:
quote:
Quote:
... It only turned a particular field in my DB into links. Now these links open only one file which should not be the case....
Well, sure it did, the way you coded it.

You did:
      <A HREF="REZ_APPLICATION.pdf"><%= oRs.Fields("Link")%></A>
So *EVERY* link will go to "REZ_APPLICATION.pdf"

*MY* suggestion was to use
     <A HREF="<%=oRs("Link")%>" > <%=oRs("Name")%> </A>

You SAID that you have your users enter BOTH a name AND a link. So if you store BOTH the name and link in the DB--and if you then *retrieve* both link and name--you have two separate values and you can use them separately for the purpose intended! One is the link, so it goes in the HREF, where a link would logically go. The other is the name, so *that* is what you display to the user. (The link is hidden in the HTML.)

Now, the other major mistake you have is your SQL query.

You are doing
    oRs.Open "SELECT Link FROM Orders",oConn
so that *ONLY* gets you the LINK from the table.

You *need* to get BOTH the name and link:
    oRs.Open "SELECT Link, Name FROM Orders",oConn
Code:
Set oRs=Server.CreateObject("ADODB.Recordset")
oRs.Open "SELECT Link, Path FROM Orders",oConn
oRs.MoveFirst
<TABLE BORDER=1 COLS=<% = oRs.Fields.Count %>>
   <TR>
    <%Dim oField 
    For Each oField In oRs.Fields %>
      <TH> <% = oField.Name %></TH>
      <% Next %>
      </TR>

<%Do While Not oRs.EOF %>
   <TR>
   <%For Each oField In oRs.Fields%>
       <TD ALIGN=RIGHT>
    <%If oField.Name = "Link" Then%>
   <A HREF= "<%= oRs.Fields("Path")%>" > <%= oRs.Fields("Link")%>  </A>
            <%Elseif oField.Name = "Path" Then
                Response.Write "&nbsp;"
            Elseif IsNull(oField) Then
                Response.Write "&nbsp;"
                  End If
                %>
        </TD>
       <% Next
       oRS.MoveNext%>
       </TR>
    <% Loop %>
</TABLE>
<%    
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing
%>
Hi there,
     From My SQL statement i now get two fields show up (Link and Path)
    But I changed the logic to make "Path" display a space because when i had "oField.Value" it displayed some sort of code that i could not understand (You probably would like to know that the Data type for my Field named "Path" is an OLE Object in MS Access)
    However, I have still not been able to execute a document by clicking on a text in my Field (Link). Please if you can find anything wrong with the way I have coded above please let me know.

Thank You

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a local file from a hosted link FishBoy Classic ASP Professional 1 November 27th, 2007 11:08 AM
opening files wilbur C# 1 April 20th, 2005 05:54 AM
Select distinct data from one column madkaikar_ashish SQL Server 2000 1 December 17th, 2004 10:25 AM
Distinct Column Occurrences jemacc SQL Server 2000 2 October 25th, 2004 04:20 AM
Opening Files Read-Only SerranoG Access VBA 5 May 6th, 2004 02:40 PM



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


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