<%@LANGUAGE="VBSCRIPT" %> <% 'Connection to Microsoft SQL Server from ASP Option Explicit Response.Buffer = True On Error Resume Next 'A System DSN does NOT need to be set up for this example. 'Dimension variables Dim oConn Dim oRS Dim SQL 'Set up DB connection Set oConn = Server.CreateObject("ADODB.Connection") 'Set up Recordset Set oRS = Server.CreateObject("ADODB.Recordset") ' Create ODBC connection string & open connection ' The example below assumes you are using the northwind database oConn.ConnectionString = "Driver=SQL Server;UID=yourUserID;Password=yourPass;SERVER=sotdev4.tech.purdue.edu;database=yourDB" Call oConn.Open 'Prepare SQL statement SQL = "SELECT DISTINCT ContactTitle FROM Customers" 'Execute the query and store result in oRS Set oRS = oConn.Execute(SQL) 'oRS.EOF means the next row is the End Of File. 'Each value in oRS.Fields("") is a column name in the table. 'Writing oRS.Fields("columnName") will return the value of that cell in the DB. While not oRS.EOF Response.Write(oRS.Fields("ContactTitle") & "
" & chr(13)) oRS.MoveNext() wend 'Close all object references oRS.Close Set oRS = Nothing oConn.Close Set oConn = Nothing %>