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

Let’s 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 a long time but, still, there are some websites running in Classic ASP which needs 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>")

%>

 

Leave a Reply

Theme: Overlay by Kaira
Agurchand