
Using RecordSets within Access 2000 Data Access Pages
Why are you using 3 objects (a command, recordset and connection), when only
one (a connection) is needed?
<%
strSQL= "INSERT INTO gpDocument FIELDS" & _
"(GroupCode,FolderID,DocName,ObjectName) " & _
"Values" & _
"(''511','FolderLink','" & DocSyFile.Form("name") & "','savename')"
Set DocSys_Conn = Server.CreateObject("ADODB.Connection")
DocSys_Conn.ConnectionTimeout = Session("DocSys_ConnectionTimeout")
DocSys_Conn.Open Session("DocSys_ConnectionString"),
Session("DocSys_RuntimeUserName"), Session("DocSys_RuntimePassword")
DocSys_Conn.Execute strSQL
DocSys_Conn.Close
%>
??
Only a fraction of the code and a single object instead of 3 (which
conserves server resources). What are you gaining by opening a command and
recordset object here?
Furthermore, I've often seen the use of two objects (recordset and
connection) to do an AddNew, but why add a command object, too? Even an
AddNew with just a recordset and connection would take less code and use
fewer server resources.
Kurt
Quote:
> The same way. Below is part of a code (on ASP using
VBScript):
> REM Set database connection and open recordset
> Set DocSys_Conn = Server.CreateObject("ADODB.Connection")
> DocSys_Conn.ConnectionTimeout = Session("DocSys_ConnectionTimeout")
> DocSys_Conn.CommandTimeout = Session("DocSys_CommandTimeout")
> DocSys_Conn.Open Session("DocSys_ConnectionString"),
> Session("DocSys_RuntimeUserName"), Session("DocSys_RuntimePassword")
> Set cmd = Server.CreateObject("ADODB.Command")
> Set Data = Server.CreateObject("ADODB.Recordset")
> cmd.CommandText = "gpDocument"
> cmd.CommandType = adCmdTable
> Data.CursorType = adOpenKeyset
> Data.LockType = adLockOptimistic
> Set cmd.ActiveConnection = DocSys_Conn
> Data.Open cmd
> REM Insert a new record
> Data.AddNew
> REM Assign values to columns of newly created record
> Data("GroupCode") = "511"
> Data("FolderID") = FolderLink
> Data("DocName") = DocSysFile.Form("name")
> Data("ObjectName") = savename
> REM Save values
> Data.Update
> REM Close connection
> Data.Close
> DocSys_Conn.Close
> Set Data = Nothing
> Set cmd = Nothing
> Set DocSys_Conn = Nothing
> The above code works on Access 97 and 2000 and SQL Server 6.5 and 7.0
> (probably on all databases).
> Hope this helps.
> > I have an Access 2000 Data Access Page, on which I want to delete and
> create
> > Database Records.
> > I am using VB Script to perform validation on the form, and in this
script
> I
> > want to create & delete Database Records. In Access I would normally
use
> > something like:\
> > RecordSet.Addnew
> > RecordSet.Update
> > How do I do this in VB Scripts?
> > Thanks for any help.
> > Andrew