Connect to Database (ASP)

The following connects to a database with ASP JScript:

<%
// create connection
var oConn = Server.CreateObject("ADODB.Connection");
// open connection to database
oConn.Open(CONNECTION_STRING);
// generate SQL
sSQL = "SELECT * FROM tablename";
// create recordset from SQL
var oRS = oConn.Execute(sSQL);
// work with recordset
Response.Write(oRS("fieldname"));
// close recordset and connection
oRS.Close();
oConn.Close;
%>

And with ASP VBScript:

<%
Dim oConn, sSQL, oRS
' create connection
Set oConn = Server.CreateObject("ADODB.Connection")
' open connection to database
oConn.Open(CONNECTION_STRING)
' generate SQL
sSQL = "SELECT * FROM tablename"
' create recordset from SQL
Set oRS = oConn.Execute(sSQL)
' work with recordset
Response.Write(oRS("fieldname"))
' close recordset and connection
oRS.Close()
Set oRS = Nothing
oConn.Close()
Set oConn = Nothing
%>

Comments

Popular posts from this blog

Select box manipulation with jQuery

Basic Excel Spreadsheet Generation (ASP/ASP.NET)

Link: HTML Agility Pack (.NET)