I have been looking into using database transactions in the environment I am currently programming in (C#.Net WebPages with WebMatrix, using SQL Server CE), and have read up a lot on the topic.
At first, I was looking into this because I felt it was 100% necessary for my project, although, now I realize that the default "Last-in-wins" concurrency policy will work fine for my somewhat simple CRUD system.
Now, I don't have enough knowledge about this to really say that I, 100%, need this, but I would like to, if possible, converge all of the statements I would otherwise have to hit the database several times for, into one statement, so as to minimize the number of times the database has to be locked (again, I'm not sure if this is worth worrying over, but it just feels like a single statement would cleaner, more efficient, and possibly even less error-prone).
In my server-side code, I have some logical branches that, depending on whether ID numbers can be reused or not, needs to perform an INSERT INTO
or an UPDATE
statement to the database for each row that I need to add. Problem is there is no way, other than transactions, to combine multiple UPDATE
and/or INSERT
statements into one communicable statement.
Lastly, in reviewing transaction syntax for my environment myself, I came across many pages that describe how transactions work, but provide no syntactical examples thereof. I did find this page...:
http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlcecommand.transaction(v=vs.100).aspx
...that actually targets my environment and server-side code, exactly, however, the syntax used does not show up with Intellisence as I'm typing, which has always been a tell-tale sign that the syntax is wrong. In this page, though, I can easily see how logically I should set this up (using 'try', 'catch', and even 'finally'), and that makes perfect sense to me. My problem is that I can't find any syntax for my given environment on how to actually compile a transaction.
Is there anyone who could possibly provide an example for the syntax needed to compile a database transaction with multiple INSERT
and UPDATE
statements, within my C#.Net WebPages with WebMatrix, using SQL Server CE, environment?