Display Data from Database in Classic ASP – Learn it here!

Lets start how we can connect to the database and pull the records from a Table using Classic ASP.

Yes, we all know people stopped using Classic ASP for long time but, still there are some website running in Classic ASP which need some modifications right?

No worries, here is the entire script for you enjoy!


<%

Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
'User (local) or localhost or your host ip
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = mydatabase; User Id = myusername; Password=mypassword"

dim strSQL
strSQL = "select * from table_name"
Set rst = conn.Execute(strSQL)

Response.Write("<table>")
If rst.BOF And rst.EOF Then
' No data
Else
Do While (Not rst.EOF)
Response.Write "<tr><td>" & rst("columnname1") & "</td><td>" & rst("columnname2") & "</td></tr>"
rst.MoveNext
Loop
End If

Response.Write("</table>")

%>

Add a Comment

Your email address will not be published. Required fields are marked *