Set objRS = Server.CreateObject( "ADODB.Recordset" )
objRS.CursorLocation = adUseClient
objRS.Fields.Append "Product", adBSTR
objRS.Fields.Append "Quantity", adInteger
objRS.Fields.Append "Unit Price", adCurrency
An empty record now exists; you just need to set the values.
objRS.Fields( "Product" ).value = "1969 Camero RS"
objRS.Fields( "Quantity" ).value = 3
objRS.Fields( "Unit Price" ).value = 2000.40
And finally Update() is called to save the changes.
ADO Added Value
If that were all, using ADO in this way would be no better than using
arrays. However, you now get to use all that great functionality
built into ADO. Let's look at some specific examples.
There are many methods available in ADO used for data manipulation. A
popular feature is sorting. Instead of writing code to sort an array
you can store the data in an ADO Recordset object and sort it.
objRS.Sort = "Product"
This creates a temporary index based on the Product field, so when
the records are accessed they will be returned in a sorted order.
Data in a recordset can be streamed out as a string. An example of
its use is building a comma-delimited file to import into Excel. Here
is an example:
asString = objRS.GetString( adClipString, , "," )
The method GetString() starts at the current cursor position, so be
sure to call MoveFirst if you intend to stream all the records. The
parameters to GetString() allow you to control the number of rows to
convert, the column delimiter, the row delimiter and the expression
used for a NULL field.
Persisting data to a file so that a data structure can be
reconstructed later is tedious if you are using standard data types,
since you have to create your own persistence mechanism. ADO has
persistence built in so you get it for free. To write your recordset
to a file just call Save() .
objRS.Save "theOrder.dat", adPersistADTG
The file type in this case is "Advanced Data Tablegram" format. This
is a proprietary Microsoft format, so it is only really useful for
storing a recordset in a file. The only other option is adPersistXML.
To reconstruct the recordset from the file just do the following:
Set objRS2 = Server.CreateObject( "ADODB.Recordset" )
|[ 1 ]