% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' Selected constants from adovbs.inc: Const adClipString = 2 ' Declare our variables... always good practice! Dim cnnGetString ' ADO connection Dim rstGetString ' ADO recordset Dim strDBPath ' Path to our Access DB (*.mdb) file Dim strDBData ' String that we dump all the data into Dim strDBDataTable ' String that we dump all the data into ' only this time we build a table ' MapPath to our mdb file's physical path. strDBPath = Server.MapPath("db_scratch.mdb") ' Create a Connection using OLE DB Set cnnGetString = Server.CreateObject("ADODB.Connection") ' This line is for the Access sample database: 'cnnGetString.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";" ' We're actually using SQL Server so we use this line instead. ' Comment this line out and uncomment the Access one above to ' play with the script on your own server. cnnGetString.Open "Provider=SQLOLEDB;Data Source=10.2.2.133;" _ & "Initial Catalog=samples;User Id=samples;Password=password;" _ & "Connect Timeout=15;Network Library=dbmssocn;" ' Execute a simple query using the connection object. ' Store the resulting recordset in our variable. Set rstGetString = cnnGetString.Execute("SELECT * FROM scratch") ' Now this is where it gets interesting... Normally we'd do ' a loop of some sort until we ran into the last record in ' in the recordset. This time we're going to get all the data ' in one fell swoop and dump it into a string so we can ' disconnect from the DB as quickly as possible. strDBData = rstGetString.GetString() ' Since I'm doing this twice for illustration... I reposition ' at the beginning of the RS before the second call. rstGetString.MoveFirst ' This time I ask for everything back in HTML table format: strDBDataTable = rstGetString.GetString(adClipString, -1, _ "
" Response.Write strDBDataTable Response.Write " |
Here's the unformatted version:
" & vbCrLf Response.Write "" & vbCrLf Response.Write strDBData Response.Write "" & vbCrLf ' That's all folks! %>