Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Construct ADO Recordset in ASP

Status
Not open for further replies.

metsey

Programmer
Mar 2, 2001
49
US
I am looking for a way to create an "virgin" ADO recordset object from scratch without connecting to a datasource. I want to build the fields and populate them with data from data posted from the form of a html page.

I have never had a problem creating a virgin recordset object (via rs.fields.append) in VB6 but in ASP I am having problems constructing the code (the smart assistant does not pop down methods for some objects which makes me assume they don't exist)

Any help would be appreciated.
 
what are you trying to do ??
you're trying to append another field ???

or you can use SQL statement.

*JJ26*
 
I am taking the contents of a posted form into a recordset object which means I need to build it from the ground up (create it - add fields - then populate it). The problem is that ADO in VBScript does not seem to have this capability like it does in VB6.
 
hope this what u mean

Code:
Dim Conn
Dim Rs

set Conn = server.CreateObject("adodb.connection")
set rs = server.CreateObject("adodb.recordset")

Conn.open  "DRIVER={SQL Server};UID=your_UserID;PWD=your_password;DATABASE=dbname;SERVER=Server_name;"

'you can select  any kind of Queries which's will be held in recordset

Rs.open "select * from your_table",Conn
If not Rs.EOF then
   Do while Not Rs.EOF
      response.write Rs(&quot;field_nm&quot;) & &quot;<br>&quot;
      Rs.MoveNext
   Loop
End If
Rs.Close

'to insert / delete / update your table
Conn.Execute  &quot;Insert into table1 (field1,field2, field3) values ('&quot; & var1 & &quot;', '&quot; & var2 & &quot;' , &quot; & var3 & &quot;) &quot;


:eek:) *JJ* :eek:)
 
Hi, I noticed you stressed WITHOUT a datasource.

The following VBScript code creates a disconnected RS from scratch then poplates it.

-----------------
Dim oRS

Sub CreateRS()

Set oRS = CreateObject(&quot;ADODB.Recordset&quot;)

'---Set up disconnected RS
oRS.ActiveConnection = Nothing
oRS.LockType = 4 'adLockBatchOptimistic
oRS.CursorLocation = 3 'adUseClient

oRS.Fields.Append &quot;ID&quot;, 3 'of type adInteger
oRS.Fields.Append &quot;Field2&quot;, 200, 10 'of type adVarChar
oRS.Fields.Append &quot;Field3&quot;, 200, 10 'of type adVarChar

oRS.Open

AddNewRec 1, &quot;aa&quot;, &quot;ab&quot;
AddNewRec 2, &quot;ba&quot;, &quot;bb&quot;
AddNewRec 3, &quot;ca&quot;, &quot;cb&quot;

End Sub

Sub AddNewRec(i1, s2, s3)

With oRS
.AddNew
.Fields(0) = i1
.Fields(1) = s2
.Fields(2) = s3
End With

End Sub
----------------

Hope this helps somewhat.
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top