ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 14th, 2012, 03:31 PM
kaed kaed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 5 kaed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 sec
Reputation Power: 0
Display all items in column from database table

I have a database called ForSale with a column Subject. I want to display all the items under subject on my homepage through ASP only (I can't use PHP).

I tried this:
Code:
set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "DSN=forsale"
objconn.Open
  
Dim strSQL
strSQL = "SELECT Subject FROM ForSale"
  
Dim objRS
set objRS = objConn.Execute(strSQL)

response.write(objRS)
  
objConn.close
set objConn = nothing


But it didn't work as it shoots me an error from response.write(objRS). I am new to ASP and very confused with this atm.

Reply With Quote
  #2  
Old August 14th, 2012, 05:07 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
Here's a place to start your learning http://msdn.microsoft.com/en-us/lib...64%28v=vs.90%29
You can't response.write an object.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
  #3  
Old August 15th, 2012, 01:03 PM
kaed kaed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 5 kaed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 sec
Reputation Power: 0
Figured it out. And it would have been better if you posted this instead a link to the w3schools ADO page.

Here's the code for future reference and I also added so it would only display the subjects from the past 14 days (and not the dates too).
Code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "DSN=forsale"
conn.Open

sql = "SELECT Subject, DatePosted FROM ForSale WHERE ((([DatePosted])<Now()) And (([DateRemove])>Now() Or ([DateRemove]) Is Null)) And ((([Display])=True)) ORDER BY DatePosted DESC"

set rs = conn.execute(sql)

do until rs.EOF
  If rs("DatePosted")> DateAdd("D", -14 , Now) Then 'no posts over 14 days old
	  dim i
	  i = 0
	  for each x in rs.Fields 'loops through both columns (Subject & DatePosted)
		Response.Write("<li><a href='/ForSale/forsale.asp'>" & x.value & "</a></li>")
		i = i + 1
		if i = 1 then exit for 'this is added to keep from displaying the DatePosted column
	  next
  end if
  rs.MoveNext 'next row
loop

rs.close
conn.close
%>

Reply With Quote
  #4  
Old August 15th, 2012, 10:53 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
Quote:
And it would have been better if you posted this instead a link to the w3schools ADO page.
Oh, I didn't realize you just wanted copy & paste code without understanding. Sorry.

Reply With Quote
  #5  
Old August 16th, 2012, 03:26 PM
kaed kaed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 5 kaed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 sec
Reputation Power: 0
Quote:
Originally Posted by Doug G
Oh, I didn't realize you just wanted copy & paste code without understanding. Sorry.


From your grumpy comment I realized I must have done something unnecessary in the code. So I looked through it and figured the for loop was stupid of me to add.

Now my code is:
Code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "DSN=forsale"
conn.Open

sql = "SELECT Subject, DatePosted FROM ForSale WHERE ((([DatePosted])<Now()) And (([DateRemove])>Now() Or ([DateRemove]) Is Null)) And ((([Display])=True)) ORDER BY DatePosted DESC"

set rs = conn.execute(sql)

do until rs.EOF
  If rs("DatePosted")> DateAdd("D", -14 , Now) Then 'no posts over 14 days old
		Response.Write("<li><a href=/ForSale/forsale.asp#" & Replace(rs("Subject"), " ", "") & "'>" & rs("Subject") & "</a></li>")
  end if
  rs.MoveNext 'next row
loop

rs.close
conn.close
%>


Everything in the code (except the do until rs.EOF and the variable names) are mine. I also understand everything in the code. Still grumpy?

Reply With Quote
  #6  
Old September 7th, 2012, 04:18 AM
haowangy haowangy is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 haowangy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 29 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Quote:
Originally Posted by kaed
I have a database called ForSale with a column Subject. I want to display all the items under subject on my homepage through ASP only (I can't use PHP).

I tried this:
Code:
set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "DSN=forsale"
objconn.Open
  
Dim strSQL
strSQL = "SELECT Subject FROM ForSale"
  
Dim objRS
set objRS = objConn.Execute(strSQL)

response.write(objRS)
  
objConn.close
set objConn = nothing


But it didn't work as it shoots me an error from response.write(objRS). I am new to ASP and very confused with this atm.

I am new to ASP and very confused with this atm.

Reply With Quote
  #7  
Old November 24th, 2012, 01:57 AM
ghyupdc ghyupdc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 ghyupdc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 6 sec
Reputation Power: 0
From your grumpy comment I realized I must have done something unnecessary in the code. So I looked through it and figured the for loop was stupid of me to add.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Display all items in column from database table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap