Display data from a SQL server database

In this example we will display data from our storename database that we used in our previous example . adding to a SQL server database .

Code :

<%
'now we will deal with the ado constants that are required
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTable = 2
Dim objConn , objRS
'create instances of Connection and Recordset objects
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'open our storename database
objConn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;"& _
"User ID=sa;Initial Catalog=storename;Data Source=SERVERNAME"
'open the storename table
objRS.Open "storename" , objConn , adOpenForwardOnly , adLockReadOnly , adCmdTable
'loop through all data in the table
While Not objRS.EOF
Response.Write objRS.Fields("name") & "&nbsp"
Response.Write objRS.Fields("email") & "&nbsp"
Response.Write "<br>"
objRS.MoveNext
Wend
'close everything
objRS.Close
objConn.Close
'destroy objects
Set objRS = nothing
Set objConn = Nothing
%>

Notes :

Change the Data Source in the connection string to your servers name . In this example the User ID is SA with no password , this is not recommended for normal use but this is a test example so we have used it.

Sponsors