The answer I like the best is a stored_proc that way I can update or create with one sqlo call but, in all truth it depends on what you are doing.
Originally Posted by Pluto
I would suggest the sql and the insert for most items that way you could do something like the following
You do need to watch out for single quotes in you data since they will break you sql string.
sql = "INSERT INTO MyTable (Name, Address) VALUES('" & Name & "', '" & Address & "')"
In this way you do not have to even open a recordset to execute your insert, but if you are checking to see if the record exist you may want to do it this way.
And of course my favorite would be the following
sql = "SELECT * FROM MyTable where Name = '" & Name & "'"
oRs.Open sql, oCn, 2, 3
IF oRs.EOF then
oRs("Name") = Name
oRs("Address") = Address
Then just call the stored proc via a sql query and a execute.
CREATE Procedure sp_UpdateMyTable
DECLARE @nCnt int
SELECT @nCt = count(*)
WHERE Name = @Name
IF (@nCnt > 0)
SET Name = @Name, Address = @Address
INSERT INOT MyTable