AllExperts > Experts 
Search      

Active Server Pages Programming (ASP)

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Srini Nagarajan
Expertise
I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience
Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.
 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Asp Programming

Topic: Active Server Pages Programming (ASP)



Expert: Srini Nagarajan
Date: 9/25/2007
Subject: Asp Programming

Question
how to disply information from database use asp

Answer
Hi

Here is simple code to retrieve and display from database
html><head>
<TITLE>dbsimple.asp</TITLE>
</head>
<body bgcolor="#FFFFFF">
<%
' this code opens the database
myDSN="DSN=Student;uid=student;pwd=magic"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN

' this code retrieves the data
mySQL="select * from publishers where state='NY'"
set rstemp=conntemp.execute(mySQL)

' this code detects if data is empty
If rstemp.eof then
   response.write "No records matched<br>"
   response.write mySQL & "<br>So cannot make table..."
   connection.close
   set connection=nothing
   response.end
end if
%>
<table border=1>
<%
' This code puts fieldnames into column headings
response.write "<tr>"
for each whatever in rstemp.fields
   response.write "<td><B>" & whatever.name & "</B></TD>"
next
response.write "</tr>"

' Now lets grab all the records
DO UNTIL rstemp.eof
   ' put fields into variables
   pub_id=rstemp("pub_id")
   pub_name=rstemp("pub_name")
   city=rstemp("city")
   state=rstemp("state")
   country=rstemp("country")

   ' write the fields to browser
   cellstart="<td align=""top"">"
   response.write "<tr>"
   response.write  cellstart & pub_id & "</td>"
   response.write  cellstart & pub_name & "</td>"
   response.write  cellstart & city & "</td>"
   response.write  cellstart & state & "</td>"
   response.write  cellstart & country & "</td>"

   response.write "</tr>"
   rstemp.movenext
LOOP
%>
</table>

<%
' Now close and dispose of resources
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</body></html>


-srini

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.