basic ASP, ADO question

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default basic ASP, ADO question

    I am trying to build a simple page in classic ASP code
    that queries a SQL table based on user input. I have
    sample code, but it isn't quite what I want...
    On page init I don't want a listing of all the records for
    LastName in Authors (Pubs), but it is listing them. I can
    move the list to the top of the page or the bottom of the
    page, but I don't know how to get rid of the list, but
    still return a record when the user enters a name and
    clicks submit. Would appreciate any help or samples for
    this. I just took ASP.NET class, easy to do there because
    of the events page_load and button_click; but I don't know
    classic ASP.
    Here is the VB and Form code I have:

    Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
    adOpenForwardOnly = 0
    adLockReadOnly = 1
    adCmdTable = 2

    Dim objConn, objRS, strName
    set objConn = Server.CreateObject("ADODB.Connection")
    set objRS = Server.CreateObject("ADODB.Recordset")

    objConn.Open "DSN=mydatabase" 'connects to Pubs
    Dim strDatabaseType
    strDatabaseType = "SQL"
    Dim strSQL ' SQL string
    strSQL = "SELECT LastName, FirstName FROM Employees"
    dim lngRecs
    <h1>Find Author</h1>
    <form name=NameInfo action="FindByName.asp" method="post">
    Enter Last name for author:
    <input type="text" name="Name"><br><br>
    <br> <INPUT TYPE=SUBMIT VALUE="Find"> <input
    type=reset value="Clear">
    </form>
    <%
    If Request.Form("Name") <> "" Then
    strName = Request.Form("Name")
    strSQL = strSQL & " WHERE LastName LIKE '" & Request.Form
    ("Name") & "'"
    End If

    Set objRS = objConn.Execute(strSQL, lngRecs, 1) 'adCmdText
    %>
    'Create the ordered list & cleanup
    <% Do While Not objRS.EOF %>
    <LI><% = objRS.Fields("LastName") %></LI>
    <% objRS.MoveNext
    Loop %>
    <%
    set objConn = Nothing
    set objRS = Nothing
    %>
    </body>
    </html>
    DMS Guest

  2. Similar Questions and Discussions

    1. Basic FLV question
      Can someone please help me. we wish to stream flv files using Flash Media Server 2. we have installed the program however we are at a loss as to how...
    2. basic 3d question
      Hi, Just a qiuck question....I have created a 3d world and exported it to director. I want to add a basic cube shape I create in 3dstudio max to...
    3. Basic Question
      Hello, I've noticed in some sample code that sometimes people use the @ before a string when concatenating them. Example: string filePath =...
    4. Basic question b/w ASP & ASP .NET
      I would like to know what is the basic difference between ASP and ASP .NET VB AND VB .NET ADO and ADO .NET look forward to your responses
    5. basic css question
      In several of my posts lately, I have made it known that I am nto a huge fan of using newer stuff as opposed to older methods of getting things...
  3. #2

    Default Re: basic ASP, ADO question

    Add a response.write strSQL to see what SQL you are actually running
    before you run it on the server, to see if there is anything odd in it.

    DMS wrote:
    > I am trying to build a simple page in classic ASP code
    > that queries a SQL table based on user input. I have
    > sample code, but it isn't quite what I want...
    > On page init I don't want a listing of all the records for
    > LastName in Authors (Pubs), but it is listing them. I can
    > move the list to the top of the page or the bottom of the
    > page, but I don't know how to get rid of the list, but
    > still return a record when the user enters a name and
    > clicks submit. Would appreciate any help or samples for
    > this. I just took ASP.NET class, easy to do there because
    > of the events page_load and button_click; but I don't know
    > classic ASP.
    > Here is the VB and Form code I have:
    >
    > Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
    > adOpenForwardOnly = 0
    > adLockReadOnly = 1
    > adCmdTable = 2
    >
    > Dim objConn, objRS, strName
    > set objConn = Server.CreateObject("ADODB.Connection")
    > set objRS = Server.CreateObject("ADODB.Recordset")
    >
    > objConn.Open "DSN=mydatabase" 'connects to Pubs
    > Dim strDatabaseType
    > strDatabaseType = "SQL"
    > Dim strSQL ' SQL string
    > strSQL = "SELECT LastName, FirstName FROM Employees"
    > dim lngRecs
    > <h1>Find Author</h1>
    > <form name=NameInfo action="FindByName.asp" method="post">
    > Enter Last name for author:
    > <input type="text" name="Name"><br><br>
    > <br> <INPUT TYPE=SUBMIT VALUE="Find"> <input
    > type=reset value="Clear">
    > </form>
    > <%
    > If Request.Form("Name") <> "" Then
    > strName = Request.Form("Name")
    > strSQL = strSQL & " WHERE LastName LIKE '" & Request.Form
    > ("Name") & "'"
    > End If
    >
    > Set objRS = objConn.Execute(strSQL, lngRecs, 1) 'adCmdText
    > %>
    > 'Create the ordered list & cleanup
    > <% Do While Not objRS.EOF %>
    > <LI><% = objRS.Fields("LastName") %></LI>
    > <% objRS.MoveNext
    > Loop %>
    > <%
    > set objConn = Nothing
    > set objRS = Nothing
    > %>
    > </body>
    > </html>
    Greg Griffiths Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139