Solved

publish result set from a Stored Procedure result from SQL SERVER into an ASP

Posted on 2007-03-26
7
225 Views
Last Modified: 2012-06-27
I need 2 basic pages in ASP. I have the iis setup and server with the database. This is what I need
I need 2 ASP pages:
1. connection
2. Datapage with a print button.
 I want to able to call a page and view result set out of 2 stored procedures from a SQL Server DB. I am looking for a just read only data, I don't need edit functinality with it.  And have the ability to print the result set.

It could be just as simple as first name , last name test page.asp.

Thanks

0
Comment
Question by:Khanax
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:YZlat
Comment Utility

Set conn = server.CreateObject("ADODB.Connection")
conn.Open "your database connection string here"
Set rs = server.CreateObject("ADODB.recordset")
sql = "SELECT col1, col2, col3 from table"
rs.Open sql,conn
If Not (rs.Eof and rs.bof) Then
 while not rs.eof
      Response.write rs("col1") & "<br>"
      Response.write rs("col2") & "<br>"
      Response.write rs("col3") & "<br>"
 wend
end if
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
for stored procedure try

Set conn = server.CreateObject("ADODB.Connection")
conn.Open "your database connection string here"
Set rs = server.CreateObject("ADODB.recordset")

rs=conn.execute "exec storedProcedureName"
If Not (rs.Eof and rs.bof) Then
 while not rs.eof
      Response.write rs("col1") & "<br>"
      Response.write rs("col2") & "<br>"
      Response.write rs("col3") & "<br>"
 wend
end if

0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Just a slight change to YZLat's solution (no points please):

Set conn = server.CreateObject("ADODB.Connection")
conn.Open "your database connection string here"
'  Set rs = server.CreateObject("ADODB.recordset")       '  There is no need to instatiate this object, the Execute method does that.

Set rs = conn.execute "exec storedProcedureName"       ' rs is an object and therefore requires Set in VB classic.
' If Not (rs.Eof and rs.bof) Then                                        ' The While on its own will cover the case when there are no matching rows.
 while not rs.eof
      Response.write rs("col1") & "<br>"
      Response.write rs("col2") & "<br>"
      Response.write rs("col3") & "<br>"
 wend
'end if
rs.Close                                      ' Don't forget to close it.
Set rs = Nothing                         ' Release the object and recover the memory
cn.Close                                      ' Don't forget to close it.
Set cn = Nothing                         ' Release the object and recover the memory
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Khanax
Comment Utility
This is returning the all the code on the webpage.  What am I doing wrong.

Set conn = server.CreateObject("ADODB.Connection")
conn.Open  "PROVIDER=SQLOLEDB;SERVER=local;UID=sa;PWD=;DATABASE=TEST"
'  Set rs = server.CreateObject("ADODB.recordset")       '  There is no need to instatiate this object, the Execute method does that.

Set rs = conn.execute "exec TEST.DBO.NAME_TABLE"       ' rs is an object and therefore requires Set in VB classic.
' If Not (rs.Eof and rs.bof) Then                                        ' The While on its own will cover the case when there are no matching rows.
 while not rs.eof
      Response.write rs("FIRSTNAME") & "<br>"
      Response.write rs("LASTNAME") & "<br>"
 wend
'end if
rs.Close                                      ' Don't forget to close it.
Set rs = Nothing                         ' Release the object and recover the memory
cn.Close                                      ' Don't forget to close it.
Set cn = Nothing                         ' Release the object and recover the memory
0
 

Author Comment

by:Khanax
Comment Utility
This is what I did
I created a folder called Hello

Placed this folder in wwwroot folder in INETPUB

then I went to the iis manger and click on page to browse.

Thanks
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Try changing this:
Set rs = conn.execute "exec TEST.DBO.NAME_TABLE"

To:
Set rs = conn.execute "SELECT FIRSTNAME, LASTNAME TEST.DBO.NAME_TABLE WHERE <your condition goes here>"
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
Comment Utility
Let's try that again:
Set rs = conn.execute "SELECT FIRSTNAME, LASTNAME FROM TEST.DBO.NAME_TABLE WHERE <your condition goes here>"
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now