[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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

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
Khanax
Asked:
Khanax
  • 3
  • 2
  • 2
1 Solution
 
YZlatCommented:

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
 
YZlatCommented:
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
 
Anthony PerkinsCommented:
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
KhanaxAuthor Commented:
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
 
KhanaxAuthor Commented:
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
 
Anthony PerkinsCommented:
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
 
Anthony PerkinsCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now