[英]update insert msaccess
i wish to update or insert if missing into an msaccess database using asp. 我希望使用asp更新或插入msaccess数据库中。
i was trying something like: 我正在尝试这样的事情:
IF EXISTS (SELECT * FROM Table1 WHERE Column1='SomeValue')
UPDATE Table1 SET (...) WHERE Column1='SomeValue'
ELSE
INSERT INTO Table1 VALUES (...)
and 和
UPDATE Table1 SET (...) WHERE Column1='SomeValue'
IF @@ROWCOUNT=0
INSERT INTO Table1 VALUES (...)
INSERT or UPDATE by themselves work fine. INSERT或UPDATE本身工作正常。 but when i use the both with one of the methods it fails.
但当我使用其中一种方法时,它失败了。
You cannot run two sql statements at once in Access. 您无法在Access中一次运行两个sql语句。 You must update and insert in two separate operations.
您必须更新并插入两个单独的操作。
Set db = CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
db.Open "DSN=name"
rs.CursorLocation = 3
rs.Open "SELECT * FROM Table WHERE Field="&Variable, db, 3, 3
if rs.EOF then
rs.AddNew
end if
rs("fieldName1") = Variable1
rs("fieldName2") = Variable2
rs("fieldName3") = Variable3
rs.Update
rs.Close
if the SELECT returns nothing, it adds record. 如果SELECT没有返回任何内容,则会添加记录。 after adding the cursor is on the added record.
添加光标后,添加记录。 if the SELECT returns a record (since Field is unique) the cursor is on the selected record.
如果SELECT返回一条记录(因为Field是唯一的),则光标位于所选记录上。
and than it updates the record where cursor is :) 并且它更新光标所在的记录:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.