Upsert - Efficient Update or Insert in VB.Net, SQL Server
Posted
by
HK1
on Stack Overflow
See other posts from Stack Overflow
or by HK1
Published on 2012-10-19T16:58:34Z
Indexed on
2012/10/19
17:00 UTC
Read the original article
Hit count: 268
I'm trying to understand how to streamline the process of inserting a record if none exists or updating a record if it already exists. I'm not using stored procedures, although maybe that would be the most efficient way of doing this.
The actual scenario in which this is necessary is saving a user preference/setting to my SettingsUser table.
In MS Access I would typically pull a DAO recordset looking for the specified setting. If the recordset comes back empty then I know I need to add a new record which I can do with the same recordset object. On the other hand, if it isn't empty, I can just update the setting's value right away. In theory, this is only two database operations.
What is the recommended way of doing this in .NET?
© Stack Overflow or respective owner