ASP link back to Access database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TrvlOrm

    #1

    ASP link back to Access database

    I am having great difficulty in these asp scripts, using VBscript and
    JavaScript.

    I have 4 files that all need to be linked together.

    The first file "Books.html " - needs to search for a Book title, author
    or ISBN number from a Access database called "Books.mdb" . When the
    user clicks Submit from the "Books.html " file (after inputting info in
    a text box and clicking the required box to define Title, Author or
    ISBN), the information is then filtered through "Books.asp" file and
    "CreateTable.as p" file.

    <PLEASE SEE MY FILES and coding below this message, didn't know how to
    attach files - files below: Books.asp; Books.inc; Books.html and
    CreateTable.asp . Not shown is Books.mdb Access database file.

    My problem is this: I cannot get the script in the Books.asp file to
    only bring up certain information pertaining to that in my search box
    from the "Books.html " file. What happens, is a) I get a error message
    when I try and debug it or b) the full table comes up.

    HELP !

    I am using Abysse web server under http://localhost port8080.

    Can anyone please help.. Any feedback most appreciated. My personal
    e-mail is ksorman@shaw.ca for any step by step instructions you can
    offer.

    Thank you so much.

    PS - yah, you guessed it, this is a URGENT request too. :)

    Code:
    "BOOKS.ASP file"
    Code:
    <HTML>
    
    <!--#INCLUDE FILE="Books.inc" -->
    <!--#INCLUDE FILE="ADOVBS.inc" -->
    <!--#INCLUDE FILE="CreateTable.asp" -->
    
    <HEAD>
    
    <TITLE>Accessing a Data Store using DSN (Data Source Name) with Active
    Server Pages </TITLE>
    
    </HEAD>
    <BODY>
    
    <%
    Dim objConn
    Dim objRec
    
    Dim CheckISBN
    Dim CheckTitle
    Dim CheckAuthor
    Dim SearchString
    Dim found
    
    objConn.Open strConnect
    objRec.Open "Titles",strConnect,adOpenStatic,adLockReadOnly,adCmdTable
    objRec.MoveFirst
    Response.Write CreateTable(objRec)
    
    found=0
    CheckISBN=Request.Form("chkISBN")
    CheckTitle=Request.Form("chkTitle")
    CheckAuthor=Request.Form("chkAuthor")
    
    SearchString=Request.Form("txtSearch")
    
    Set objConn=Server.CreateObject("ADODB.Connection")
    Set objRec=Server.CreateObject("ADODB.RecordSet")
    
    objConn.Open strConnect
    
    objRec.Open "Titles",strConnect,adOpenStatic,adLockReadOnly,adCmdtable
    objRec.MoveFirst
    
    If CheckISBN = "ByISBN" Then
    objRec.Find "ISBN= '"& Request.Form("txtSearch") & "'"
    
    If Not objRec.EOF Then
    found=1
    Response.Write objRec("ISBN")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Price")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Title") & "<BR>"
    End if
    End if
    
    If CheckTitle = "ByTitle" Then
    objRec.Find "Title= '"& Request.Form("txtSearch") & "'"
    
    If Not objRec.EOF Then
    found=1
    Response.Write objRec("ISBN")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Price")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Title") & "<BR>"
    End if
    End if
    
    If CheckAuthor = "ByAuthor" Then
    objRec.Filter = "Author= '"& Request.Form("txtSearch") & "'"
    
    While Not objRec.EOF
    If objRec("Author") = SearchString Then
    found=1
    Response.Write objRec("ISBN")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Price")
    Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Response.Write objRec("Title") & "<BR>"
    End if
    
    objRec.MoveNext
    Wend
    If found=0 Then
    Response.Write "Record Not Found"
    End if
    End if
    
    objRec.Close
    objConn.Close
    Set objRec=Nothing
    Set objConn=Nothing
    
    
    </BODY>
    </HTML>
    Code:
    BOOKS.INC file
    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Location specific records in a database, with DSN and Active
    Server Pages </TITLE>
    
    </HEAD>
    
    <BODY>
    
    <%
    strConnect = "Driver={Microsoft Access Driver
    (*.mdb)};DBQ=c:\inetpub\wwwroot\K_Orman\Books.mdb;"
    %>
    
    </BODY>
    </HTML>
    Code:
    BOOKS.HTML file
    <HTML>

    <HEAD>

    <TITLE> Location Specifc Records - Active Server Pages, Connecting to
    DSN - PART 3</TITLE>

    </HEAD>

    <BODY>

    <FORM NAME="frmsearch " ACTION="Books.a sp" METHOD="Post">

    <H3> Please enter the Title, the Author, or the ISBN number of the
    book(s) you wish to search for: </H3>

    <INPUT TYPE="text" NAME="txtSearch "><BR>

    Search by: <BR>

    <INPUT TYPE="checkbox" NAME="chkTitle" VALUE="ByTitle" > Title <BR>
    <INPUT TYPE="checkbox" NAME="chkAuthor " VALUE="ByAuthor "> Author <BR>
    <INPUT TYPE="checkbox" NAME="chkISBN" VALUE="ByISBN"> ISBN
    <BR><BR><BR>
    <INPUT TYPE="submit" NAME="cmdSearch " VALUE="Search"> <BR>
    <INPUT TYPE="Reset" NAME="cmdreset" VALUE="Reset">
    </FORM>

    </BODY>
    </HTML>
    [/code]

    Code:
    CREATETABLE.asp file
    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE> Active Server Pages - Data Name Source </TITLE>
    
    </HEAD>
    
    <BODY>
    
    <%
    Function CreateTable(objRecordset)
    
    Dim fldField
    Dim strTable
    
    strTable = "<TABLE BORDER=2>" & "<TR ALIGN=CENTER>"
    
    For Each fldField in objRecordset.Fields
    strTable = strTable & "<TD>" & fldField.Name & "</TD>"
    Next
    
    strTable = strTable & "</TR>"
    
    While not objRecordset.EOF
    strTable = strTable & "<TR ALIGN=CENTER>"
    
    For Each fldField in objRecordset.Fields
    strTable= strTable & "<TD>" & fldField.Value & "</TD>"
    Next
    
    strTable= strTable & "</TR>"
    objRecordset.MoveNext
    
    Wend
    
    strTable = strTable & "</TABLE>"
    
    CreateTable = strTable
    
    End Function
    
    %>
    
    </BODY>
    </HTML>
    [/quote][/code] THANK YOU SO MUCH.....
  • kaeli

    #2
    Re: ASP link back to Access database

    In article <fa9bacd0.04061 80950.15f4fd8f@ posting.google. com>,
    ksorman@shaw.ca enlightened us with...[color=blue]
    > I am having great difficulty in these asp scripts, using VBscript and
    > JavaScript.
    >[/color]

    I didn't see any javascript.
    But, I'm pretty okey-dokey with VBScript, so...
    [color=blue]
    > I have 4 files that all need to be linked together.
    >
    > My problem is this: I cannot get the script in the Books.asp file to
    > only bring up certain information pertaining to that in my search box
    > from the "Books.html " file. What happens, is a) I get a error message
    > when I try and debug it or b) the full table comes up.
    >
    > HELP !
    >[/color]

    My guess is that you're not getting the search string you think you are.
    [color=blue]
    > CheckISBN=Reque st.Form("chkISB N")
    > CheckTitle=Requ est.Form("chkTi tle")
    > CheckAuthor=Req uest.Form("chkA uthor")
    >[/color]

    Write these to output with a Request.Write and end the page there (test
    page if you want).
    I bet they don't match
    [color=blue]
    >
    > If CheckISBN = "ByISBN" Then[/color]

    that sort of thing.

    I bet you get a one or a true. That is, CheckISBN will either be "1" or
    "true" which would completely mess up your query and cause the selection
    of all records.
    Checkboxes get passed as true/false, I think...
    like chkISBN=true in the query string.

    Just change the method of the form to get and look at the URL to see if
    you don't want to write the stuff on the page.

    --
    --
    ~kaeli~
    Never mess up an apology with an excuse.



    Comment

    • Trvl Orm

      #3
      Re: ASP link back to Access database

      Thanks Kaeli,

      You probably guessed that I'm new at this vbscripting code thing - so
      would you please reply with the correct code to the specific file that
      needs it. Or send me a e-mail.

      I'm a bit lost in your reply.

      Thanks.


      *** Sent via Devdex http://www.devdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • kaeli

        #4
        OT: Re: ASP link back to Access database

        In article <40d342f3$0$164 25$c397aba@news .newsgroups.ws> ,
        ksorman@shaw.ca enlightened us with...[color=blue]
        > Thanks Kaeli,
        >
        > You probably guessed that I'm new at this vbscripting code thing - so
        > would you please reply with the correct code to the specific file that
        > needs it. Or send me a e-mail.
        >
        > I'm a bit lost in your reply.
        >[/color]

        Okay, I did a little check. My idea was not what was causing the
        problem. But it was something similar.
        Your search string is empty. For some reason,
        SearchString=Re quest.Form("txt Search")
        is returning a blank. I don't know why, since it shows in the URL when I
        do a GET and from POST when I loop through all form elements (see test
        file).

        This smacks of a school assignment, so you may want to ask your teacher.
        The following is a test I did to see what the form was submitting. Run
        it and you'll see what's wrong. I don't know if it's a server thing or
        what. I've never seen this problem with unencoded forms. I gotta go home
        now, so you won't see a reply from me 'til Monday.

        test.asp
        <HTML>
        <HEAD>
        <TITLE> Location Specifc Records - Active Server Pages, Connecting to
        DSN - PART 3</TITLE>
        </HEAD>
        <BODY>
        <FORM NAME="frmsearch " ACTION="test1.a sp" METHOD="post">
        <H3> Please enter the Title, the Author, or the ISBN number of the
        book(s) you wish to search for: </H3>
        <INPUT TYPE="text" NAME="txtSearch "><BR>
        Search by: <BR>
        <INPUT TYPE="checkbox" NAME="chkTitle" VALUE="ByTitle" > Title <BR>
        <INPUT TYPE="checkbox" NAME="chkAuthor " VALUE="ByAuthor "> Author <BR>
        <INPUT TYPE="checkbox" NAME="chkISBN" VALUE="ByISBN"> ISBN
        <BR><BR><BR>
        <INPUT TYPE="submit" NAME="cmdSearch " VALUE="Search"> <BR>
        <INPUT TYPE="Reset" NAME="cmdreset" VALUE="Reset">
        </FORM>
        </BODY>
        </HTML>

        test1.asp
        <%@ Language=VBScri pt %>
        <html>
        <head>
        <title>Untitl ed Document</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>

        <body>
        <p>This is a test page for the form submit values.</p>
        <p>
        CheckISBN=<%= Request.Form("c hkISBN") %>
        CheckTitle=<%= Request.Form("c hkTitle") %>
        CheckAuthor=<%= Request.Form("c hkAuthor") %>
        SearchString=<% Request.Form("t xtSearch") %>
        </p>
        <%
        Dim f
        For Each f In Request.Form
        Response.Write f & " = "
        Response.Write Request.Form(f) & "<br>"
        Next
        %>
        </body>
        </html>


        --
        --
        ~kaeli~
        Can you be a closet claustrophobic?



        Comment

        Working...