If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Need help with this code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-03, 11:54
GREG K GREG K is offline
Registered User
 
Join Date: Feb 2003
Posts: 3
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>
Reply With Quote
  #2 (permalink)  
Old 02-25-03, 11:58
GREG K GREG K is offline
Registered User
 
Join Date: Feb 2003
Posts: 3
To be specific I only want to retrieve the body of messege id 1047
Reply With Quote
  #3 (permalink)  
Old 02-25-03, 12:50
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
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?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old 02-25-03, 14:03
GREG K GREG K is offline
Registered User
 
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
Reply With Quote
Reply

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On