HOWTO: Change Information in a Database from ASPID: Q188713
|
There are two different methods for performing updates and inserts. One way is to create a recordset and then insert/update its records. The other way is to use the Execute method to issue a SQL statement which inserts/updates the records.
The code below illustrates opening a recordset and then adding and altering
its records. The current location in the recordset determines which record
will be updated.
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Session("DSN=MyDSN")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "MyTable", conn, 1, 3, 2 ' Make sure the LockType
' allows for insertions and updates
' Insert a record
rs.AddNew
rs("Field1") = Value1
rs.Update
' Update the current record
rs("Field1") = Value2
rs.Update
rs.Close
%>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDSN"
' Insert a record
conn.Execute("INSERT INTO MyTable(Field1,Field2) VALUES (Value1,
Value2))
' Update a record
conn.Execute("UPDATE MyTable SET Field1 = Value1 WHERE Field1 = Value2")
conn.Close
%>
Additional query words: kbnokeyword
Keywords : kbADO kbASP kbGrpASP
Version : WINDOWS:97,97sp1,97sp2,97sp3; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: May 27, 1999