Certainly! A function like the one below encapsulates the process of getting a read-only recordset out the database. If you pass it a valid connection string or connection object in the varConnection parameter and a valid record-returning SQL query in the strSQL parameter, it will pass back a disconnected recordset. You can modify the function to return editable recordsets (recordsets that don't have a lock type of adLockReadOnly as below for example).
<% Function GetRecordset(varConnection, strSQL) Const adOpenStatic = 3 Const adLockReadOnly = 1 Const adUseClient = 3 Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset") ' Set cursor location: objRS.CursorLocation = adUseClient objRS.Open strSQL, varConnection, adOpenStatic, adLockReadOnly
' Disconnect, close and return: Set objRS.ActiveConnection = Nothing Set GetRecordset = objRS End Function %>
Examples of usage:
<% ' WITH AN EXISTING CONNECTION OBJECT: Response.Write _ GetRecordset(objConn _ , "SELECT * FROM tblScripts").GetString(2, -1) ' --- OR --- ' WITH A CONNECTION STRING: Response.Write _ GetRecordset("Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\InetPub\CodeLibrary\data\CodeLibrary2000.mdb" _ , "SELECT * FROM tblScripts").GetString(2, -1) %>
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.