I'm trying to build an SQL statement that will insert or update a row in the database depending on whether it exists in the table already. This format seems to work when I interface to an MSSQL server, but does not work when I use an OLEDB connection to MS Access.
IF EXISTS(select * from Resistors where ID = 2816)
update Resistors set
[Part Number]='1234'
where ID = 2816
else
insert into Resistors (
[Part Number]
)
values(
'1234'
)
;
I have validated these two sql commands using the OLEDB connection to MS Access. They work properly but now with the IF EXISTS() portion of the command.
update Resistors set
[Part Number]='1234'
where ID = 2816
insert into Resistors (
[Part Number]
)
values(
'1234'
)
The IF EXISTS() statement appears to match other documentation I have seen on the internet but I must be doing something wrong.
This is the error I receive when I run the command.
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
This is my connection string
connection.ConnectionString = "Provider = Microsoft Office 12.0 Access Database Engine OLE DB Provider; Data source = " + _database_path;
Is the exists command not supported by this connection interface? Is there a version that supports the exists command?
If Exists()code here?