Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Posts
    3

    Unanswered: Need help with this code

    I need to modify this to pull only one field out of the database. It returns all the fields. I'm modifying my home page to pull a record out of the forums.


    <% @Language = VBScript %>
    <%


    Option Explicit
    Response.Expires = -1
    %>
    <%
    Dim oConn, sConnString, CharQuery, CharRS

    Set oConn = Server.CreateObject("ADODB.Connection")
    ' User id (UID) and password (PWD) are optional, I use "sa" as the standard default
    ' sa = system administrator; I recommend not bothering using passwords and user login
    ' cause it can become a hassle if you opena and close the database alot
    ' especially from different programs and languages.
    sConnString = "DSN=-------;Database=-------;UID=sa;PWD=;"
    oConn.Open sConnString
    CharQuery = "SELECT * FROM messages" ' select <all fields> from <Your Table Name>
    set CharRS = oConn.execute(CharQuery) ' Do it!
    ' Until we hit an empty record (you must have atleast 1 record in the database or you will get an error) output the values
    if not CharRS.EOF then
    CharRS.MoveFirst
    %>
    <H3>Table listing of Members</H3>
    <table border="1">
    <tr>
    <td width="50" bgcolor="#666699"><font color="#FFFFFF"><b>ID</b></font></td>
    <td width="200" bgcolor="#666699"><font color="#FFFFFF"><b>Username</b></font></td>
    <td width="200" bgcolor="#666699"><font color="#FFFFFF"><b>Password</b></font></td>
    </tr>
    <%
    do until CharRS.EOF
    %>
    <tr>
    <% ' field name is case sensitive%>
    <td width="50"><%=CharRS("messageid")%></td>
    <td width="200"><%=CharRS("lasteditedname")%></td>
    <td width="200"><%=CharRS("body")%></td>
    </tr>
    <%
    CharRS.MoveNext
    loop
    CharRS.Close ' we are done close it
    %>
    </table>
    <%
    end if
    set CharRS = nothing ' not required but recommended
    %>



    <html>
    <head>
    </head>
    <body bgcolor=#FFFFFF text=#000000 background="images/large_bg.jpg">

    </body>
    </html>

  2. #2
    Join Date
    Feb 2003
    Posts
    3
    To be specific I only want to retrieve the body of messege id 1047

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Originally posted by GREG K
    To be specific I only want to retrieve the body of messege id 1047
    I'm probably missing something, but to get 1 field (column) just do "SELECT columnname" instead of "SELECT *"

    And if you only want the record where messageid=1047 then add " WHERE messageid=1047"

    i.e.

    CharQuery = "SELECT body FROM messages WHERE messageid=1047"

    Is that what you meant?

  4. #4
    Join Date
    Feb 2003
    Posts
    3
    Dude all I have to say to you is

    YOU ROCK< YOU ROCK HARD MAN

    lol thanks a ton

Posting Permissions

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