Refresh msaccess insert

I want to update or paste if not in msaccess database using asp.

I tried 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 themselves work fine. but when I use both methods with one of the methods, it fails.

+3
source share
2 answers
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 SELECT returns nothing, add a record. after adding the cursor to the added record. if SELECT returns a record (because the field is unique), the cursor is on the selected record.

and then updates the record the cursor is in :)

0
source

You cannot run two SQL queries in Access at once. You must update and insert two separate operations.

+1

Source: https://habr.com/ru/post/1752911/


All Articles