The following code will cause an error when running (the identifier cannot be determined for the newly inserted row), that is, the new record cannot be assigned the value of the newly generated identifier for another field of its own. This situation can be passed in Access, but not in SQL. It can be solved by searching on Baidu Method, found that many people have the same problem but cannot find a solution:
Copy the code code as follows:
set rs=server.CreateObject(adodb.recordset)
rs.open select * from t1,conn,1,3
rs.addnew()
rs(data)=abc123
rs.update
rs(data)=rs(id)
rs.update
rs.close
conn.close
(Note: The id field is the identity value (identity(1,1)))
Under a SQL database, only the following methods can be used:
Copy the code code as follows:
dim newID
set rs=server.CreateObject(adodb.recordset)
rs.open select * from t1,conn,1,3
rs.addnew()
rs(data)=abc123
rs.update
newID=rs(id)
'Note here that cursorType must be 1 to correctly obtain the identification value, and it must be obtained after update()
rs.close
rs.open select * from t1 where id= &newID,conn,1,3
rs(data)=newID
rs.update
rs.close
conn.close