I have an application that reads and writes to table in SQL Server 2005. I know the basics of reading and writing to a table.
If there is no Id then I create a new entry. If there is an Id I update the existing entry.
What is the best way to write the SqlCommand string based upon if it already exists or is new?
I can’t see writing two methods when it would then take updating two places when it came time for changes.
Any tips or tricks would be appreciated.
Here is full sample of working code you need , all you need to do is check if record already exists then update it or just insert it.
Results will be
Then you can use this stored proc from your
SqlCommandin C# (recommended)Or your can just use this SQL statement from your C#
SqlCommand(not recommended and tested)